iOS 提示框

iOS 8.0 之后UIAlertController彈框代替了UIAlertView彈框 和 UIActionSheet下彈框

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

//模態彈出提示框 相當于UIAlertView show 的方法 
[self presentViewController:alertController animated:YES completion:nil];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容