iOS9后 彈出框

//初始化一個一個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];


效果及原文地址:

效果
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容