【学习ios之路:UI系列】UIProgressView

实现类似读取数据进度条效果

代码如下: ①创建UIProgressView对象 1)定义属性

{NSTimer *_proTimer;//计时 }@property (nonatomic, retain) UIProgressView *proView;//显示进度信息@property (nonatomic, retain) UILabel *proLabel;@property (nonatomic, assign) float proValue;//保存进度值 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];= CGRectMake(10, 260, 300, 100);= 0; = [UIColor orangeColor];= [UIColor greenColor];= CGAffineTransformMakeScale(1.0f,15.0f);//添加到当前的试图上[];//释放[self.proView release];

②设置Label显示进度值,

= [[UILabel alloc] initWithFrame:CGRectMake(100, 300, 120, 30)];= [UIColor clearColor];= [*100];[];[self.proLabel release];

③创建计时器,平处理事件

//通过计时器循环改进度值_proTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES];//处理事件- (void)changeProgress {+= 0.05;= self.proValue;= [NSString stringWithFormat:@”loading%1.f%%”,self.proValue * 100];if (self.proValue >= 1) {self.proValue = 0;= @”进度完成”;//停止计数器[_proTimer invalidate];}}

,只要功夫深,铁棒磨成绣花针。

【学习ios之路:UI系列】UIProgressView

相关文章:

你感兴趣的文章:

标签云: