警告对话框&等待提示器

 1 @synthesize alertView = _alertView;
 2 @synthesize activityIndicator = _activityIndicator;
 3 
 4 - (void)viewDidLoad {
 5     [super viewDidLoad];
 6 
 7     for(int i=0;i<2;i++){
 8         UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 9         
10         btn.frame = CGRectMake(100, 100+i*100, 100, 40);
11         
12         if(i==0)
13         {
14             [btn setTitle:(@"警告提示框") forState:UIControlStateNormal];
15         }
16         else if(i==1)
17         {
18             [btn setTitle:(@"等待指示器") forState:UIControlStateNormal];
19         }
20         btn.tag = 101 + i;
21         
22         [btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
23         
24         [self.view addSubview:btn];
25     }
26 
27 }
28 
29 -(void) pressBtn:(UIButton *) btn
30 {
31     if(btn.tag == 101)
32     {
33         _alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"您的电量过低" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"朕知道了",@"11",@"22", nil];
34         [_alertView show];
35     }else if(btn.tag == 102)
36     {
37         //宽度高度不可变
38         _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 500,80,80)];
39         
40         _activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
41         
42         self.view.backgroundColor = [UIColor blackColor];
43         
44         [self.view addSubview:_activityIndicator];
45         
46         [_activityIndicator startAnimating];
47     }
48    
49     
50 }
51 //当点击对话框的按钮时,调用此函数
52 -(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
53 {
54     NSLog(@"index = %ld
",buttonIndex);
55     
56 }
57 
58 //对话框即将消息,此函数被调用
59 
60 -(void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
61 {
62     NSLog(@"will dismiss");
63     
64 }
65 
66 
67 -(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
68 {
69     NSLog(@"have already dismissed");
70     
71 }
72 
73 - (void)didReceiveMemoryWarning {
74     [super didReceiveMemoryWarning];
75     // Dispose of any resources that can be recreated.
76 }
77 
78 
79 @end
 1 @interface ViewController : UIViewController<UIAlertViewDelegate>
 2 {
 3     //定义一个警告提示框
 4     UIAlertView* _alertView;
 5     //定义一个等待提示对象,转圈
 6     UIActivityIndicatorView* _activityIndicator;
 7     
 8 }
 9 
10 //属性定义
11 @property(retain,nonatomic) UIAlertView* alertView;
12 
13 @property(retain,nonatomic) UIActivityIndicatorView* activityIndicator;
原文地址:https://www.cnblogs.com/vector11248/p/7593283.html