iOS笔记UI--UIProgressView(进度条)

声明:此为本人学习笔记,若有纰漏错误之处的可留言共同探讨

/*

注意点:

 进度条的progress范围是 0.0 - 1.0  

*/

View部分

#import "MyProgressView.h"

@implementation MyProgressView

+(MyProgressView *)initWithFrame:(CGRect)frame TrackTintColor:(UIColor *)trackTintColor ProgressTintColor:(UIColor *)progressTintColor {
    MyProgressView *myProgressView = [[MyProgressView alloc]init];
    myProgressView.frame = frame;
   
    //进度条还没加载完的颜色
    myProgressView.trackTintColor = trackTintColor;
    
    //进度条已经加载完的颜色
    myProgressView.progressTintColor = progressTintColor;
    return myProgressView ;
}
@end

VC部分

#import "ViewController.h"
#import "MyProgressView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadingUI];
}

#pragma mark - 更新UI
-(void)loadingUI {
    MyProgressView *progressView =[MyProgressView initWithFrame:CGRectMake(100, 100, 100, 100) TrackTintColor:[UIColor blueColor] ProgressTintColor:[UIColor redColor]];
    [self.view addSubview:progressView];
    
    // 进度条起始位置
    progressView.progress = 0.3;
    progressView.tag = 93;
    
    // 定时器
    //    [NSTimer timerWithTimeInterval:1 target:self selector:@selector(progressAdd:) userInfo:nil repeats:nil];
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(progressAdd) userInfo:nil repeats:YES];
    
}

#pragma mark - 进度条
-(void)progressAdd {
    UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:93];
    progressView.progress += 0.01;
    if (1 == progressView.progress ) {
        progressView.progress = 0;
    }
}


附上完整Demo:http://download.csdn.net/detail/csdn_hhg/9229643


你可能感兴趣的:(进度条,UI,ios,UIProgressView,OC--UI功能)