UIActivityIndicatorView:
.h文件
@interface UIActivityIndicatorViewController : UIViewController {
UIActivityIndicatorView * myActivityView;
}
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *myActivityView;
-(IBAction)onClickButton: (id)sender;
@end
.m文件
#import "UIActivityIndicatorViewController.h”
@implementation UIActivityIndicatorViewController
@synthesize myActivityView;
-(IBAction)onClickButton: (id)sender {
if ([myActivityView isAnimating]) {
[myActivityView stopAnimating];
} else {
[myActivityView startAnimating];
}
}
- (void)dealloc {
[myActivityView release];
[super dealloc];
}
@end
UIProgressView
.h文件
@interface ProgressViewViewController : UIViewController {
UIProgressView *Progress;
NSTimer *timer;
}
@property (nonatomic, retain) IBOutlet UIProgressView *Progress;
@property (nonatomic, assign) NSTimer *timer;
-(IBAction)start;
@end
.m文件
@synthesize Progress;
@synthesize timer;
-(IBAction)start{
Progress.progress = 0.0;
timer = [NSTimer
scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(update)
userInfo:nil repeats:YES];
}
NSTimer是可以隐式地启动一个线程,scheduledTimerWithTimeInterval指定线程要休眠多少时间调用一次,selector所指定的方法update
-(void)update{
Progress.progress = Progress.progress + 0.1;
if (Progress.progress == 1.0) {
[timer invalidate];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"任务通知"
message:@"硬盘格式化完成!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)dealloc {
[Progress release];
[super dealloc];
}
UIProgressView控件的progress属性是0.0~1.0烦范围。0.0时候在开始的位置,1.0时候是进度到了100%。