xcode -饼状进度条
生活随笔
收集整理的這篇文章主要介紹了
xcode -饼状进度条
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
界面搭建
創建一個畫餅狀的類 ?eatView 集成UIView
#import "eatView.h"@implementation eatView// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect {//創建一個園的風格數組NSArray * arr = @[@10,@10,@10,@10,@10,@10,@10,@10,@10,@10];//計算園的中心點CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);//園的半徑CGFloat radius = rect.size.width * 0.5 ;//開始位置CGFloat startA = 0;//結束位置CGFloat endA = 0;CGFloat angle = 0;//設置uiView的背景顏色self.backgroundColor=[UIColor clearColor];//遍歷園等分的數組for (NSNumber *num in arr) {//計算開始位置startA = endA;//計算弧度angle = num.intValue / 100.0 * M_PI *2;//結束位置endA =startA + angle;//創建畫筆UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];//畫一條連接中心的線 [path addLineToPoint:center];//設置隨機顏色[[self randomColor]set];[path fill];}//創建一個定時器CADisplayLink * link =[CADisplayLink displayLinkWithTarget:self selector:@selector(click)];//加入主運行時 [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];//創建一個定時器 // [NSTimer scheduledTimerWithTimeInterval:1/50.0 target:self selector:@selector(click) userInfo:nil repeats:YES]; } /**生產隨機顏色*/ - (UIColor *)randomColor{return [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]; } /**重繪圖行*/ -(void)click{[self setNeedsDisplay]; }@end View Code脫線 一根UITextField 另一根UIView
@property (weak, nonatomic) IBOutlet UITextField *textNum;
@property (weak, nonatomic) IBOutlet UIView *beginView;
拖線 UIButton 點擊方法 ?- (IBAction)beginGoBtn:(id)sender
?
#import "ViewController.h"#import "eatView.h"@interface ViewController () @property (weak, nonatomic) IBOutlet UITextField *textNum; @property (weak, nonatomic) IBOutlet UIView *beginView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }- (IBAction)beginGoBtn:(id)sender {//釋放加載過得UIview 不然又內存問題for (UIView * vol in self.beginView.subviews) {[vol removeFromSuperview];}//關閉鍵盤[self.view endEditing:YES];int count=self.textNum.text.intValue;for (int i=0; i<count; i++) {eatView * eatV = [[eatView alloc]init];// 按鈕尺寸CGFloat optionW = 50;CGFloat optionH = 50;// 按鈕之間的間距CGFloat margin = 5;// 控制器view的寬度CGFloat viewW = self.beginView.frame.size.width;// 總列數int totalColumns = 6;// 最左邊的間距 = 0.5 * (控制器view的寬度 - 總列數 * 按鈕寬度 - (總列數 - 1) * 按鈕之間的間距)CGFloat leftMargin = (viewW - totalColumns * optionW - margin * (totalColumns - 1)) * 0.5;int col = i % totalColumns;// 按鈕的x = 最左邊的間距 + 列號 * (按鈕寬度 + 按鈕之間的間距)CGFloat optionX = leftMargin + col * (optionW + margin);int row = i / totalColumns;// 按鈕的y = 行號 * (按鈕高度 + 按鈕之間的間距)CGFloat optionY = row * (optionH + margin);eatV.frame = CGRectMake(optionX, optionY, optionW, optionH);[self.beginView addSubview:eatV];}}@end
?
?
效果圖:
?
轉載于:https://www.cnblogs.com/fleas/p/5618519.html
總結
以上是生活随笔為你收集整理的xcode -饼状进度条的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [读书笔记]机器学习:实用案例解析(6)
- 下一篇: 使用yum安装CDH Hadoop集群