UIProgress的简单使用

       UIProgress的取值范围为0-1,通过setProgress为其设置值,很多时候和NSTimer联合起来使用。

       例子:

@property (strong, nonatomic) UIProgressView *progress;  
@synthesize progress;


- (void)viewDidLoad

{

//定义大小及位置

     self.progress = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 910, 768, 20)];

//设置进度条类型

    [self.progress  setProgressViewStyle:UIProgressViewStyleDefault]; 

//初始化的0值

    [self.progress setProgress:0];

//添加到父视图

    [self.view addSubview:self.progress];

	timecount  = 0;//当前播放时间初始化为0

     float playtime = 30; //定义播放时间为30秒

     showTimer =[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(checkShoutouts:) userInfo:nil repeats:YES ];//设置定时器

}


//设置setProgress的值


-(void)checkShoutouts
{
     timecount = timecount+1;
    [self.progress setProgress:(timecount / playTime)]; 

}

       UIPorgress是进度条,在任何你想要显示进度的地方,需要调用它,progressViewStyle设置不同,进度条的显示样式也不同,需要通过Timer定时跑任务修改UIProgress的显示值。

你可能感兴趣的:(UIProgress)