ios警告與提示對話方塊

來源:互聯網
上載者:User

標籤:

  進行iOS開發過程中,不可避免的使用到各種提醒,來提醒使用者當前操作,或是為了警告,或是為了資料緩衝。

  本文介紹了使用 UIAlertController和UIAlertAction兩個類,完成三種狀態的提醒。

這裡首先使用UIAlertController建立一個提示對話方塊,按照Factory 方法即可快速建立,參數UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert。

填寫完提示的標題和內容後,就可以使用UIAlertAction建立一個具體的按鈕行為了。參數UIAlertActionStyle有三種樣式, UIAlertActionStyleDefault(普通)、UIAlertActionStyleCancel(取消)、UIAlertActionStyleDestructive(警告(破壞性的))。預設狀態是正常藍色字型,取消狀態時字型加粗,而警告狀態字型則會變為紅色。當只添加一個行為對象時,行為對象會顯示在UIAlertController對象的下面,添加2個時,並排顯示,添加3個及以上者,按列顯示。

  你可以很方便的在任意一個事件響應函數中,添加以下代碼,並在塊語句中添加當使用者選擇相應的選項時執行的語句。

 

    //使用UIAlertController建立一個提示對話方塊,只有標題和資訊    //UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert        //使用UIAlertAcion建立具體的行為,同時添加三個則按列顯示    //UIAlertActionStyle有三種樣式,普通、取消、警告(破壞性的)    //UIAlertActionStyleDefault、UIAlertActionStyleCancel(字型加粗顯示)、UIAlertActionStyleDestructive(字型紅色顯示)        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"標題" message:@"messagebox" preferredStyle:UIAlertControllerStyleAlert];        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"確認" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {    }];    UIAlertAction *action2= [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {    }];    UIAlertAction *action3= [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {    }];        [alert addAction:action1];    [alert addAction:action2];    [alert addAction:action3];    [self presentViewController:alert animated:YES completion:^{    }];

 

  

    

 

    

 

ios警告與提示對話方塊

聯繫我們

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