IOS UIAlertController 彈框 (ios 9.0 後代替了UIAlertView彈框 和 UIActionSheet下彈框)
[摘要:正在IOS 9.0 後 蘋果民圓宣告沒有再或沒有推舉應用UIAlertView 戰 UIActionSheet 由UIAlertController舉行取代二者 用操縱器将二者開兩為一 很簡略 輕易 上面便是閉于UIAlert]
在IOS 9.0 後 蘋果官方宣布不再或不推薦使用UIAlertView 和 UIActionSheet 由UIAlertController進行代替兩者 用控制器将兩者合二為一 很簡單 友善 下面就是關于UIAlertView的常用方法
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 建立一個BUTTON 點選顯示彈框
UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
button.frame = CGRectMake(, , , );
// 給BUTTON 添加點選方法
[button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchUpInside)];
button.backgroundColor = [UIColor blueColor];
[self.view addSubview:button];
}
// button的點選方法
- (void)actionButton:(UIButton *)button
{
// 初始化一個一個UIAlertController
// 參數preferredStyle:是IAlertController的樣式
// UIAlertControllerStyleAlert 建立出來相當于UIAlertView
// UIAlertControllerStyleActionSheet 建立出來相當于 UIActionSheet
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"靜" preferredStyle:(UIAlertControllerStyleAlert)];
// 建立按鈕
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
NSLog(@"注意學習");
}];
// 建立按鈕
// 注意取消按鈕隻能添加一個
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) {
// 點選按鈕後的方法直接在這裡面寫
NSLog(@"注意學習");
}];
// // 建立警告按鈕
// UIAlertAction *structlAction = [UIAlertAction actionWithTitle:@"警告" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction *action) {
// NSLog(@"注意學習");
// }];
//
// 添加按鈕 将按鈕添加到UIAlertController對象上
[alertController addAction:okAction];
[alertController addAction:cancelAction];
//[alertController addAction:structlAction];
// 隻有在alert情況下才可以添加文本框
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"使用者名";
textField.secureTextEntry = YES;
}];
// // 取出文本
// UITextField *text = alertController.textFields.firstObject;
// UIAlertAction *action = alertController.actions.firstObject;
// 将UIAlertController模态出來 相當于UIAlertView show 的方法
[self presentViewController:alertController animated:YES completion:nil];
}