ios警告与提示对话框
進(jìn)行iOS開發(fā)過程中,不可避免的使用到各種提醒,來(lái)提醒用戶當(dāng)前操作,或是為了警告,或是為了數(shù)據(jù)緩沖。
本文介紹了使用?UIAlertController和UIAlertAction兩個(gè)類,完成三種狀態(tài)的提醒。
這里首先使用UIAlertController創(chuàng)建一個(gè)提示對(duì)話框,按照工廠方法即可快速創(chuàng)建,參數(shù)UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert。
填寫完提示的標(biāo)題和內(nèi)容后,就可以使用UIAlertAction創(chuàng)建一個(gè)具體的按鈕行為了。參數(shù)UIAlertActionStyle有三種樣式,?UIAlertActionStyleDefault(普通)、UIAlertActionStyleCancel(取消)、UIAlertActionStyleDestructive(警告(破壞性的))。默認(rèn)狀態(tài)是正常藍(lán)色字體,取消狀態(tài)時(shí)字體加粗,而警告狀態(tài)字體則會(huì)變?yōu)榧t色。當(dāng)只添加一個(gè)行為對(duì)象時(shí),行為對(duì)象會(huì)顯示在UIAlertController對(duì)象的下面,添加2個(gè)時(shí),并排顯示,添加3個(gè)及以上者,按列顯示。
你可以很方便的在任意一個(gè)事件響應(yīng)函數(shù)中,添加以下代碼,并在塊語(yǔ)句中添加當(dāng)用戶選擇相應(yīng)的選項(xiàng)時(shí)執(zhí)行的語(yǔ)句。
?
//使用UIAlertController創(chuàng)建一個(gè)提示對(duì)話框,只有標(biāo)題和信息//UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert//使用UIAlertAcion創(chuàng)建具體的行為,同時(shí)添加三個(gè)則按列顯示//UIAlertActionStyle有三種樣式,普通、取消、警告(破壞性的)//UIAlertActionStyleDefault、UIAlertActionStyleCancel(字體加粗顯示)、UIAlertActionStyleDestructive(字體紅色顯示) UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"標(biāo)題" message:@"messagebox" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"確認(rèn)" 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:^{}];?
??
? ??
?
?? ?
?
轉(zhuǎn)載于:https://www.cnblogs.com/bravely/p/4716155.html
總結(jié)
以上是生活随笔為你收集整理的ios警告与提示对话框的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Log4j配置文件位置+Spring数据
- 下一篇: [转]VMware虚拟机上网络连接(ne