日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

xcode -饼状进度条

發布時間:2025/3/17 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 -饼状进度条的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。