// 初始化一個一個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];
}
ios9 xcode7 UIAlertController的常用用法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.