UIProgressView 作用:显示当前进度 以进度条的形式 提高用户体验
UIProgressView 有两种样式:1.UIProgressViewStyleDefault 2.UIProgressViewStyleBar
两者的区别在于进度条样式UIProgressViewStyleBar 右边为透明 即未完成部分为透明
而默认的为不透明
(上:Default,下:Bar)
ProgressView主要可以设置的属性
progress:float 类型 0 - 1 改变值可以达到改变进度显示的作用
progressTintColor
trackTintColor
progressImage
trackImage
以上四种是用来定制进度条的
下面图解上述四属性
该View使用起来也是比较容易的
直接上代码 演示效果 添加了一个定时更新progress属性的定时器 模拟进度
#import "ViewController.h"
const NSUInteger kProgressViewControllerMaxProgress = 100;
@interface ViewController ()
@property (nonatomic,strong) UIProgressView *view1;
@property (nonatomic,strong) UIProgressView *view2;
@property (nonatomic,strong) UIProgressView *view3;
@property (nonatomic,assign) int currentProgress;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
_view1 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_view2 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
_view3 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
CGPoint center = self.view.center;
_view1.frame = CGRectMake(0, 0, 200, 50);
_view2.frame = CGRectMake(0, 0, 200, 50);
_view3.frame = CGRectMake(0, 0, 200, 50);
_view1.center = CGPointMake(center.x, center.y-100);
_view2.center = CGPointMake(center.x, center.y+100);
_view3.center = CGPointMake(center.x, center.y);
[self.view addSubview:_view1];
[self.view addSubview:_view2];
[self.view addSubview:_view3];
[_view3 setTintColor:[UIColor redColor]];
[_view3 setTrackTintColor:[UIColor greenColor]];
_currentProgress = 0;
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.03f target:self selector:@selector(simulateProgress:) userInfo:nil repeats:YES];
}
- (void)simulateProgress:(NSTimer *)timer{
_currentProgress++;
if (_currentProgress>=100) {
[timer invalidate];
}
[_view1 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
[_view2 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
[_view3 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
}
that's all
thx
Everything you see on Screen is UIView.