iOS 控制元件之 UIProgressView

征途LN發表於2014-02-19

這是一個進度條檢視,使用簡單,效果明顯。

//
//  ViewController.m
//  UIProgressViewDemo
//
//  Created by 冷凝 on 14-2-19.
//  Copyright (c) 2014年 **. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UIProgressView * _progressView;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	_progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
    _progressView.frame = CGRectMake(10, 200, 300, 50);
    _progressView.progress = 0.0;  //設定初始進度值
    _progressView.progressTintColor = [UIColor redColor];//已進度部分的顏色
    //_progressView.progressImage = [UIImage imageNamed:@"1.png"];//已進度部分圖片
    _progressView.trackTintColor = [UIColor blackColor]; //未進度部分顏色
    //_progressView.trackImage = [UIImage imageNamed:@"2.png"];
    [self.view addSubview:_progressView];
    
    //啟動一個定時器,模擬進度效果
    [NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(progressGoOn:) userInfo:nil repeats:YES];
}

-(void)progressGoOn:(NSTimer*)timer{
    if (_progressView.progress < 1.0) {
        [_progressView setProgress:_progressView.progress+.02 animated:YES];
        _progressView.progress = _progressView.progress+.02;
    }else{
        _progressView.progress = 0;
    }
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end



相關文章