UIAlertController是系統提供的一個提示控件,不過現在大多數程序員都被pm逼著自定義一些更好看得提示框。。。
//聲明一個提示框
UIAlertController *myAlert= [UIAlertController alertControllerWithTitle:@"這是提示框的標題" message:@"這個提示框的內容"preferredStyle:UIAlertControllerStyleAlert];
/*preferredStyle有兩種:
屏幕中間UIAlertControllerStyleAlert
底部提示UIAlertControllerStyleActionSheet
*/
//提示框加入一些行為
UIAlertAction *no = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *yes = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil]];
/*
style:行為的種類
UIAlertActionStyleDefault = 0,確定
UIAlertActionStyleCancel,取消
UIAlertActionStyleDestructive紅色字體 重點提示
handler:block加入一些方法
*/
[myAlert addAction:yes];
[myAlert addAction:no];
[self presentViewController:myAlert animated:YES completion:nil];
//顯示在屏幕上
效果圖
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。