首页 > 其他 > 详细

UI第九节——UIProgressView

时间:2017-01-03 11:57:48      阅读:124      评论:0      收藏:0      [点我收藏+]

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 实例化 UIProgressView,高度是固定的
    UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(40, 100, 295, 30)];
   
#if 1
    // 主题颜色
    progressView.progressTintColor = [UIColor redColor];
    progressView.trackTintColor = [UIColor greenColor];
#endif
    
#if 0   // 这个有BUG,不显示
    // 图片
    progressView.progressImage = [UIImage imageNamed:@"slider_track_min"];
    progressView.trackImage = [UIImage imageNamed:@"slider_track_max"];
#endif
    
    // 把progressView加到self.view上
    [self.view addSubview:progressView];
    
    // 启动一个定时器
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerRunning:) userInfo:@{@"progressView": progressView} repeats:YES];
}

// 定时会调用一次这个函数
- (void)timerRunning:(NSTimer *)timer
{
    UIProgressView *progressView = [timer.userInfo objectForKey:@"progressView"];
    
    // 设置进度
    progressView.progress += 0.1;
    
    NSLog(@"%f", progressView.progress);
    
    // 当进度条完全走完的时候,让定时器停掉
    if (progressView.progress >= 1.0) {
        
        // 销毁定时器
        [timer invalidate];
    }
}

UI第九节——UIProgressView

原文:http://www.cnblogs.com/laolitou-ping/p/6244161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!