iOS中的UIProgressView(进度条)
2016-04-14 00:00
429 查看
UIProgressView 进度条
#import "ViewController.h" @interface ViewController (){ UIProgressView *myProgressView; UILabel *myLabel; NSTimer *myTimer; BOOL yesOrNo; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //新建一个UIProgressView,并且设置位置和大小 myProgressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 100, 300, 100)]; //设置UIProgressView的初始状态(也可以说是起点),满格是1 myProgressView.progress = 0.4; //设置UIProgressView的线条颜色(需要转到3D图,在侧面才可以看见) myProgressView.backgroundColor = [UIColor redColor]; //设置进度条的颜色 myProgressView.tintColor = [UIColor blueColor]; //不能直接设置UIProgressView的宽度,但是可以缩放ლ(°◕‵ƹ′◕ლ) myProgressView.transform = CGAffineTransformScale(myProgressView.transform, 1, 2); //将UIProgressView添加到手机界面上 [self.view addSubview:myProgressView]; //新建一个Label,来显示进度条的百分比 myLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 200, 200)]; [self.view addSubview:myLabel]; //添加一个定时器,每次的速度是0.01,并且添加方法,每0.1秒触发一次 myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(haha:) userInfo:nil repeats:YES]; } ////定时器的方法 -(void)haha:(id)a{ //如果进度条的状态没有跑满(1.0) if (myProgressView.progress<1.0) { //则进度条就加0.01 myProgressView.progress = myProgressView.progress+0.01; //myLabel的文字用来显示进度条的百分比,默认是从0.01计算的,所以乘以100 myLabel.text = [NSString stringWithFormat:@"%.0f%%", myProgressView.progress*100]; }else{ //反之如果跑满了,myLabel文字就变成了“安装成功” myLabel.text = @"安装成功"; [myTimer invalidate]; } } //定时器往返的方法 -(void)haha:(id)a{ //设置一个BOOL判断,此处如果是状态yes if (yesOrNo) { //则进度条就加0.01 myProgressView.progress = myProgressView.progress+0.01; //如果跑满了,则状态就变为no if (myProgressView.progress == 1) { yesOrNo = !yesOrNo; } //如果状态为no }else if (!yesOrNo){ //因为前面进度条跑满了,状态变为no,所以此处让进度条-0.01 myProgressView.progress = myProgressView.progress-0.01; //如果减到了0,则状态右变成了yes,一直在循环 if (myProgressView.progress == 0) { yesOrNo = !yesOrNo; } } }
相关文章推荐
- iOS中的UISegmentedControl(分段控制器)
- iOS中的UISwitch(开关)
- iOS中的UITabBarController(类似于微信首页,上面是标题,下面是联系人,通讯录等)
- Packet for query is too large (2353015 > 1048576).
- Android UI优化
- UITableView基础
- hdu-4126 Genghis Khan the Conqueror(最小生成树+树形dp)
- 设计模式之Builder模式
- 关于UICollectionView的headerView的问题
- Java continue 、break、标签
- add VNC console to KVM guests
- 奇异值分解(Singular Value Decomposition)
- ART 的 interpret-only模式源码及调用流程 & QuickCompiler后端调用流程
- 【6】mysql数据查询语言DQL(Data Query Language)①
- ios UITapGestureRecognizer 单指单击、单指多击、多指单击、多指多击事件操作
- LeetCode *** 300. Longest Increasing Subsequence
- iOS限定UITextField的输入格式
- (4)Java设计模式-建造者模式(Builder)
- 说说 UINavigationBar 中的 translucent 属性
- hdu5412 CRB and Queries (整体二分)