Welcome in my book!
QQ20150809-1@2x.png
- 這里首先使用UIAlertController創(chuàng)建一個提示對話框穆咐,按照工廠方法即可快速創(chuàng)建,參數(shù)UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert掂名。
- 填寫完提示的標(biāo)題和內(nèi)容后,就可以使用UIAlertAction創(chuàng)建一個具體的按鈕行為了哟沫。參數(shù)UIAlertActionStyle有三種樣式饺蔑, UIAlertActionStyleDefault(普通)、UIAlertActionStyleCancel(取消)嗜诀、UIAlertActionStyleDestructive(警告(破壞性的))猾警。
默認(rèn)狀態(tài)是正常藍(lán)色字體,取消狀態(tài)時字體加粗隆敢,而警告狀態(tài)字體則會變?yōu)榧t色发皿。當(dāng)只添加一個行為對象時,行為對象會顯示在UIAlertController對象的下面拂蝎,添加2個時穴墅,并排顯示,添加3個及以上者温自,按列顯示玄货。 - 你可以很方便的在任意一個事件響應(yīng)函數(shù)中,添加以下代碼捣作,并在塊語句中添加當(dāng)用戶選擇相應(yīng)的選項時執(zhí)行的語句誉结。
- (IBAction)BtnClick:(UIButton *)myAlertBtn {
//使用UIAlertController創(chuàng)建一個提示對話框,只有標(biāo)題和信息
//UIAlertControllerStyle只有一種樣式:UIAlertControllerStyleAlert
//使用UIAlertAcion創(chuàng)建具體的行為券躁,同時添加三個則按列顯示
//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:^{
}];
}