警告對話框UIAlertView和等待提示器UIActivityIndicatorView:
1.UIAlertView簡單一點就是彈框
2.就是所謂的菊花轉圈圈
聲明:注意@interface ViewController : UIViewController
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwcmUgY2xhc3M9"brush:java;">
#import
實現:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//實現屬性和成員變量的同步
@synthesize alertView =_alertView;
@synthesize activityIndicator=_activityIndicator;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for(int i=0;i<2;i++){
UIButton * btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100+100*i, 100, 40);
if(i==0){
[btn setTitle:@"警告對話框" forState:UIControlStateNormal];
}
else if(i==1){
[btn setTitle:@"等待指示器" forState:UIControlStateNormal];
}
btn.tag = 101+i;
[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
-(void) pressBtn:(UIButton*) btn{
//警告對話框創建
//p1:對話框標題
//p2:提示信息
//p3:處理按鈕事件的代理對象
//p4:取消按鈕的文字,默認的索引為0;
//p5:其他按鈕文字 ** otherButtonTitles:@"確定", nil]; 只有取消和確定按鈕是橫向排開
// otherButtonTitles:@"確定",@"確定1",@"確定2", nil];這樣子就會全部縱向排開,索引依次是1,2,3.
//p6:...:添加其他按鈕
//nil:表示按鈕添加結束
if(btn.tag==101){
_alertView = [[UIAlertView alloc]initWithTitle:@"警告"
message:@"你的手機電量過低,請保存數據"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"確定", nil];
//顯示對話框
[_alertView show];
}
//創建等待提示器,大伙都叫他菊花
else if(btn.tag==102){
//創建等待提示器,寬高不可變更
_activityIndicator =[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(100, 300, 80, 80)];
//設定提示的風格:小灰,小白,大白
_activityIndicator.activityIndicatorViewStyle =UIActivityIndicatorViewStyleGray;//小灰
// _activityIndicator.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite;//小白
//
// _activityIndicator.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhiteLarge;//大白
// self.view.backgroundColor=[UIColor blueColor];
[self.view addSubview:_activityIndicator];
//啟動動畫並顯示
[_activityIndicator startAnimating];
//停止等待動畫並隱藏
// [_activityIndicator stopAnimating];
}
}
//當點擊對話框的按鈕時,調用此函數
//p1:對話框對象本身
//p2:按鈕的索引
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"index=%ld\n",buttonIndex);
}
//對話框即將消失,此函數被調用
-(void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"即將消失!");
}
//對話框已經消失時,調用此函數
-(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"已經消失");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end