IOS開發之XCode學習014:警告對話方塊和等待提示器

來源:互聯網
上載者:User

標籤:指標   變數   ram   可變   inter   nim   ace   view   nil   

此文學習來源為:http://study.163.com/course/introduction/1002858003.htm

 

此工程檔案實現功能:

 1、警告對話方塊和等待提示器的概念

2、警告對話方塊和等待提示器的屬性

3、警告對話方塊和等待提示器的使用

 

===========================ViewController.h指令碼==============================  

@interface ViewController : UIViewController <UIAlertViewDelegate>

{

    //定義一個警告對話方塊視圖對象

    UIAlertView* _alertView;

    //等待提示對象

    //當下載或載入比較大的檔案時,可以顯示此控制項,處於提示等待狀態

    UIActivityIndicatorView* _activityIndicatorView;

}

@property (retain,nonatomic) UIAlertView* alertView;

@property (retain,nonatomic) UIActivityIndicatorView * activityIndicatorView;

@end

 

===========================ViewController.m指令碼==============================

@interface ViewController ()

@end

@implementation ViewController 

//屬性和成員變數的同步

@synthesize alertView = _alertView;

@synthesize activityIndicatorView = _activityIndicatorView;

 

- (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

{

    //警告對話方塊

    if (btn.tag == 101) {

        //建立警告對話方塊

        //P1:對話方塊標題

        //P2:提示資訊

        //P3:處理按鈕事件的代理對象

        //P4:取消按鈕的文字

        //P5:其他按鈕文字

        //P6....:添加其他按鈕

        //PLast:表示按鈕添加結束

        //兩個按鈕橫著排,多個豎著排

        _alertView = [[UIAlertView alloc] initWithTitle:@"警告"

                                          message:@"你的手機電量過低,即將關機,請儲存好資料"

                                          delegate:self

                                          cancelButtonTitle:@"取消"   //取消按鈕永遠放最後

                                          otherButtonTitles:@"OK",@"11",@"22", nil];

        //顯示對話方塊

        [_alertView show];

    }

    //建立等待提示器

    else if (btn.tag == 102)

    {

        //寬度和高度不可變更

        _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 300, 80, 80)];

        

        //設定提示的風格:小灰,小白,大白

        _activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;//UIActivityIndicatorViewStyleWhite;//UIActivityIndicatorViewStyleGray;

        

        self.view.backgroundColor = [UIColor blackColor];

        

        [self.view addSubview:_activityIndicatorView];

        

        //啟動動畫並顯示

        [_activityIndicatorView startAnimating];

    

        //停止等待動畫並隱藏

        //[_activityIndicatorView 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(@"對話方塊已經消失");

}

 

程式運行結果:

按鈕

警告對話方塊(2個按鈕:橫排)

警告對話方塊(4個按鈕:豎排)

等待指標:(大白風格)

 

學習總結:

  • 重點:警告對話方塊和等待提示器的概念
  • 痛點:警告對話方塊和等待提示器的用法

源碼連結地址:https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA  密碼:7t1l

IOS開發之XCode學習014:警告對話方塊和等待提示器

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.