1,在視圖文件中拖拽一個 Activity Indicator View並且聲明
#import <UIKit/UIKit.h> @interface XViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *myLabel; @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *myActivityIndicatorView; @end
2,運用 startAnimating 和stopAnimating方法控制菊花是否轉動
// // XViewController.m // ssss // // #import "XViewController.h" @interface XViewController () @end @implementation XViewController @synthesize myLabel; @synthesize myActivityIndicatorView; -(void)myMethodName { //加載此方法以后Label名為 welcome myLabel.text = @"welcome"; //停止動畫 [myActivityIndicatorView stopAnimating]; //將菊花隱藏掉 myActivityIndicatorView.hidden = YES; } - (void)viewDidLoad { [super viewDidLoad]; [myActivityIndicatorView startAnimating];//加載的時候動畫開始運行 //2秒后運行名為myMethodName的方法 [self performSelector:@selector(myMethodName) withObject:nil afterDelay:2.0f]; //selector(方法名)
} - (void)viewDidUnload { [self setMyLabel:nil]; [self setMyActivityIndicatorView:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end