1.在.h文件里面声明
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIActivityIndicatorView * activityView;
}
- (IBAction)onClicked:(id)sender;
@end
2.在.m文件里面实现
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
activityView=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(50, 50, 30, 30)];
[activityView setCenter:CGPointMake(160, 140)];
[activityView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activityView];
[activityView startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onClicked:(id)sender {
[activityView stopAnimating];
}
@end
startAnimating 开启方法
stopAnimating停止方法