// @interface
IBOutlet UIProgressView *progressBar;
@property (nonatomic, retain) IBOutlet UIProgressView *progressBar;
- (IBAction)startTheTimer:(id)sender;
- (void)goProgress:(NSTimer *)theTimer;
// @implementation
@synthesize progressBar;
......
---------------------------------------------------------------------------------------------------------
接著, 將 UIButton 上的 Touch Up Inside 事件, 連到以下的 startTheTimer 這個 IBAction:
- (IBAction)startTheTimer:(id)sender {
// set Progress to 0.0
[progressBar setProgress:0.0];
[NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:@selector(goProgress:) userInfo:nil repeats:YES];
}
- (void)goProgress:(NSTimer *)theTimer {
float progress = progressBar.progress;
progress = progress * 10 + 1;
[progressBar setProgress:progress * 0.1];
if (progress >= 10) {
// stop NSTimer
[theTimer invalidate];
}
}
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。