iOS界面编程-UIProgressView

一、UIProgressView介绍

      你使用uiprogressview类来描述任务发费时间的进度。一个进度条的例子是在下载邮件信息时,显示在邮件应用程序的底部。uiprogressview类提供了用于管理进度条的样式和用于获取和设置在任务完成的进度值的属性。



二、相关属性和方法

@property(nonatomic) float progress    当前的进度,取值范围为0-1,1代表任务已经完成。

- (void)setProgress:(float)progress   animated:(BOOL)animated  调整当前的进度

@property(nonatomic) UIProgressViewStyle progressViewStyle  可以设置当前进度条的类型

@property(nonatomic, strong) UIColor *progressTintColor  ;可以用来设置已填充进度条的颜色

@property(nonatomic, strong) UIImage *progressImage;用来设置已填充进度条的图像。如果设置这个值progressTintColor被忽略了

@property(nonatomic, strong) UIColor *trackTintColor;用来设置未填充进度条的颜色

@property(nonatomic, strong) UIImage *trackImage;用来设置未填充进度条的颜色。同样的则trackTintColor被忽略了。


typedef enum {

   UIProgressViewStyleDefault,

   UIProgressViewStyleBar,

} UIProgressViewStyle;

枚举代表进度条允许的类型。


三、实际例子

@interface AnotherViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>{
    double proValue;
    NSTimer *timer;
    UIProgressView *progressView;
}
@end

-(void)initProgressView{
    progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(10, 220, self.view.bounds.size.width-20, 40)];
    progressView.progress = 0.0;//设置进度条起步
    progressView.progressTintColor = [UIColor redColor];//设置已经填充进度条颜色
    progressView.trackTintColor = [UIColor greenColor];//设置未填充进度条颜色
    [self.view addSubview:progressView];
    [progressView setProgressViewStyle:UIProgressViewStyleBar];//设置进度条类型
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(20, 300, self.view.bounds.size.width-40, 44);
    btn.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(beginProgressButton:)
          forControlEvents:UIControlEventTouchUpInside];

    
}
-(void)beginProgressButton:(id)sender{

    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(progressOperator) userInfo:nil repeats:YES];
    
}

-(void)progressOperator{

    proValue++;
    if (proValue>10) {
        [timer invalidate];
    }else{
        [progressView  setProgress:proValue/10.0];
        
    }
}
}









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

house.zhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值