@interface LRUIProgressViewViewController ()
@end
@implementation LRUIProgressViewViewController{
UIProgressView *_pv;
NSTimer *_timer;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self createProgressView];
[self createTimer];
}
- (void)createProgressView
{
UIProgressView *pv= [[UIProgressView alloc] initWithFrame:CGRectMake(50, 100, 300, 1)];
_pv = pv;
[self.view addSubview:pv];
//1.设置当前值 不能设置最大值和最小值(最大值1 最小值0)
//要想使进度条进度不断的增加 那么就要不断增加progress的值
pv.progress = 0;
//2.设置进度条的样式
pv.progressViewStyle = UIProgressViewStyleBar;
/*UIProgressViewStyleDefault 蓝色进度条
UIProgressViewStyleBar 白色进度条 主要用于工具条中
*/
//3.定制进度条和轨道的颜色
pv.progressTintColor = [UIColor yellowColor];
pv.trackTintColor = [UIColor blackColor];
//4.定制进度条的图片和轨道的图片 在设置图片之前一定要先设置好拉伸图片
UIImage * image1 = [[UIImage imageNamed:@"rr_pub_checkin.png"] stretchableImageWithLeftCapWidth:50 topCapHeight:0];
UIImage * image2 = [[UIImage imageNamed:@"rr_pub_status.png"] stretchableImageWithLeftCapWidth:50 topCapHeight:0];
pv.trackImage = image1;//轨道图片
pv.progressImage = image2;//进度条图片
//5.进度条大小 位置 的改变可以使用transform
pv.transform = CGAffineTransformMakeScale(1, 10);
}
- (void)createTimer
{
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(go) userInfo:nil repeats:YES];
}
- (void)go
{
if (_pv.progress < 1) {
_pv.progress += 0.001;
}
}
进度条 UIProgressView
最新推荐文章于 2022-02-19 17:12:44 发布