iOS開發從入門到精通-- 警告對話方塊UIAlertView和等待提示器UIActivityIndicatorView

來源:互聯網
上載者:User

標籤:

警告對話方塊UIAlertView和等待提示器UIActivityIndicatorView:
1.UIAlertView簡單一點就是彈框
2.就是所謂的菊花轉圈圈


聲明:注意@interface ViewController : UIViewController<UIAlertViewDelegate>這個裡面多了一個UIAlertViewDelegate代理

#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIAlertViewDelegate>{    //定義一個警告對話方塊視圖對象    UIAlertView * _alertView;    //等待提示對象    //當下載,或者載入比較大的檔案時,可以顯示此控制項,處於提示等待狀態    UIActivityIndicatorView * _activityIndicator;}@property(retain,nonatomic) UIAlertView * alertView;@property(retain,nonatomic) UIActivityIndicatorView * activityIndicator;@end

實現:

#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

iOS開發從入門到精通-- 警告對話方塊UIAlertView和等待提示器UIActivityIndicatorView

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.