//创建进度条控件
progress=[[UIProgressView alloc]initWithFrame:CGRectMake(0, 40, 320,1)];
//设置进度条轨迹颜色 相当于背景颜色
progress.trackTintColor=[UIColor blackColor];
//设置进度条颜色
progress.progressTintColor=[UIColor redColor];
//定义空条状态为0 满条状态为1
flag=NO;
//添加按钮
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(0, 100, 320,60)];
btn.backgroundColor=[UIColor greenColor];
[btn setTitle:@"走两步" forState:UIControlStateNormal];
//添加动作
[btn addTarget:self action:@selector(walkTap) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btn];
[self.window addSubview:progress];
return YES;
}
//
-(void)walkTap
{
if(flag==NO)
{
progress.progress+=0.1;
if( progress.progress==1)
{
flag=YES;
}
}
else{
progress.progress-=0.1;
if( progress.progress==0)
{
flag=NO;
}
}
}