//初始化一個一個UIAlertController
//參數preferredStyle:是IAlertController的樣式
// UIAlertControllerStyleAlert創建出來相當于UIAlertView
// UIAlertControllerStyleActionSheet創建出來相當于UIActionSheet
UIAlertController*alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"kris"preferredStyle:(UIAlertControllerStyleAlert)];
//創建按鈕
UIAlertAction*okAction = [UIAlertActionactionWithTitle:@"確定"style:(UIAlertActionStyleDefault)handler:^(UIAlertAction*action) {
NSLog(@"注意學習");
}];
//創建按鈕
//注意取消按鈕只能添加一個
UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:@"取消"style:(UIAlertActionStyleCancel)handler:^(UIAlertAction*action) {
//點擊按鈕后的方法直接在這里面寫
NSLog(@"注意學習");
}];
////創建警告按鈕
//UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) {
//NSLog(@"注意學習");
//}];
//
//添加按鈕將按鈕添加到UIAlertController對象上
[alertControlleraddAction:okAction];
[alertControlleraddAction:cancelAction];
//[alertController addAction:structlAction];
//只有在alert情況下才可以添加文本框
[alertControlleraddTextFieldWithConfigurationHandler:^(UITextField*textField) {
textField.placeholder=@"用戶名";
textField.secureTextEntry=YES;
}];
////取出文本
//UITextField *text = alertController.textFields.firstObject;
//UIAlertAction *action = alertController.actions.firstObject;
//將UIAlertController模態出來相當于UIAlertView show的方法
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];
iOS9后 彈出框
效果
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
推薦閱讀更多精彩內容
- 轉載 http://www.cocoachina.com/ios/20141126/10320.html如果侵權,...
- iOS 8的新特性之一就是讓接口更有適應性、更靈活,因此許多視圖控制器的實現方式發生了巨大的變化。全新的UIPre...
- iOS 8的新特性之一就是讓接口更有適應性、更靈活,因此許多視圖控制器的實現方式發生了巨大的變化。全新的UIPre...