進度條 UIProgressView

@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;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章