UIProgressView-初识IOS

时间:2022-12-05 08:30:58

好几天没更新了,学的时候太紧,没时间复习了都。今天刚好有时间,多更几个。

今天复习的是UIProgressView,我们常见使用在修改某些属性的时候经常用到,比如透明度,今天我们介绍一个简单的使用例子

定义什么的,我就不多说了。前边已经介绍很多了。

    //声明一个进度条视图
_progressview = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
//设置进度条的显示位置
[_progressview setFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width - , )];
//设置进度条走过的颜色
[_progressview setProgressTintColor:[UIColor redColor]];
//设置进度条没走过的颜色
[_progressview setTrackTintColor:[UIColor greenColor]];
//设置进度条初始值
[_progressview setProgress:0.5 animated:YES];

然后我们来设置一个全局变量,来承接进度条的值,这里要注意 ,进度条的范围是0 - 1,所以一般都取0.5f 为中间值。

记得 定义完之后一定要加载视图,到现在了我也经常忘记加载

[self.view addSubview:_progressview];

我定义了三个按钮,"+","-","测试",并给他定义了方法。

    UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom];
[add setTitle:@"增加" forState:UIControlStateNormal];
[add setFrame:CGRectMake(, , , )];
[add setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[add setBackgroundColor:[UIColor greenColor]];
[add.titleLabel setFont:[UIFont systemFontOfSize:]];
[add addTarget:self action:@selector(jia) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:add]; UIButton *smal = [UIButton buttonWithType:UIButtonTypeCustom];
[smal setTitle:@"减小" forState:UIControlStateNormal];
[smal setFrame:CGRectMake(, , , )];
[smal setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[smal setBackgroundColor:[UIColor greenColor]];
[smal.titleLabel setFont:[UIFont systemFontOfSize:]];
[smal addTarget:self action:@selector(Smal) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:smal]; UIButton *ceshi = [UIButton buttonWithType:UIButtonTypeCustom];
[ceshi setTitle:@"测试" forState:UIControlStateNormal];
[ceshi setFrame:CGRectMake(, , , )];
[ceshi setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[ceshi setBackgroundColor:[UIColor greenColor]];
[ceshi.titleLabel setFont:[UIFont systemFontOfSize:]];
[self.view addSubview:ceshi]; [ceshi addTarget:self action:@selector(Aabb) forControlEvents:UIControlEventTouchUpInside];

button

相关方法

-(void)jia{
self.f = self.f+0.1;
if (self.f <= ) {
_progressview.progress = _f;
}else{
_f = 1.0;
_progressview.progress = _f;
}
}
- (void)Add{
self.f=self.f+0.1;
if (self.f <= ) {
_progressview.progress = _f;
}else{
_f = 1.0;
_progressview.progress = _f;
} }
-(void)Smal{
_f = _f-0.1;
if (_f >=) {
_progressview.progress = _f;
} else {
_f = ;
_progressview.progress = _f;
}
}
-(void)Aabb{
NSLog(@"mmmmmmmm");
}

demo

出现的效果就是随着点击按钮,f值就会随着改变,进度条的值也会明显的改变。

总的来说UIProgressView也没什么说的,基本上常用到的就这一点,根据进度条的值改变某些东西的属性值。