ios警告与提示对话框
進行iOS開發過程中,不可避免的使用到各種提醒,來提醒用戶當前操作,或是為了警告,或是為了數據緩沖。
本文介紹了使用?UIAlertController和UIAlertAction兩個類,完成三種狀態的提醒。
這里首先使用UIAlertController創建一個提示對話框,按照工廠方法即可快速創建,參數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:^{}];?
??
? ??
?
?? ?
?
轉載于:https://www.cnblogs.com/bravely/p/4716155.html
總結
以上是生活随笔為你收集整理的ios警告与提示对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Log4j配置文件位置+Spring数据
- 下一篇: [转]VMware虚拟机上网络连接(ne