定义:
@interface ViewController ()
{
UIActivityIndicatorView *testActivityIndicator;
}
实例化,开始旋转:
-(void) showWaitStatus
{
NSLog(@"wait...");
testActivityIndicator =
[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; CGRect rect = self.view.frame;
testActivityIndicator.center = CGPointMake(rect.size.width / , rect.size.height / );
[self.view addSubview:testActivityIndicator];
testActivityIndicator.color = [UIColor redColor]; // iOS5 引入指定颜色
[testActivityIndicator startAnimating]; // 开始旋转
[testActivityIndicator setHidesWhenStopped:YES]; // 当旋转结束时隐藏
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. [self showWaitStatus];
}
停止旋转:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[testActivityIndicator stopAnimating];
}