1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #import "ViewController.h"
@interface ViewController () { NSTimer *_timer; } @end
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad];
UIProgressView *progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
progressView.progress = 0.25;
progressView.progressTintColor = [UIColor redColor];
progressView.trackTintColor = [UIColor greenColor];
progressView.progressImage = [UIImage imageNamed:@"1"];
progressView.trackImage = [UIImage imageNamed:@"2"];
progressView.tag = 10;
[self.view addSubview:progressView];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerRun) userInfo:nil repeats:YES]; } -(void)timerRun{ UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:10]; if (progressView.progress < 1.0) { progressView.progress += 0.01; }else{ NSLog(@"下载完成");
[_timer invalidate]; } } @end
|