您的位置:首页 > 产品设计 > UI/UE

进度条 UIProgressView

2015-09-28 13:16 232 查看
@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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: