ios uialertcontroller 确定 取消按钮 可以自定义按钮么

如题所述

第1个回答  2016-04-27
创建工程项目和视图控制器
1、创建一个empty(空的)工程项目,新建一个UIViewController;
2、选中工程,右键-New File…选择“Cocoa Touch Class”-Next,给个合理的名称ViewController,再Next完成;
3、在AppDelegate.m文件包含#import "ViewController.h";
4、初始化创建ViewController的视图控制器,并用导航栏控制器包含。将之设置为根视图控制器。

设置UIAlertController选择风格样式
1、创建UIAlertController;
2、初始化UIAlertController,需要使用alertControllerWithTitle:message:preferredStyle:方法;
3、设置Title、message 、preferredStyle;
4、preferredStyle风格样式有两种:UIAlertControllerStyleAlert和UIAlertControllerStyleActionSheet,是分别代表要代替的UIAlertView和UIActionSheet。

显示UIAlertController
1、UIAlertController继承于UIViewController;
2、显示需要使用UIViewController的方法:presentViewController 弹出视图控制器。

添加按钮到UIAlertController
1、创建UIAlertAction作为UIAlertController的按钮项;
2、初始化使用方法了:actionWithTitle: style: handler:;
3、设置Title、 style、handler;
4、添加 UIAlertAction至UIAlertController。

显示两种不同风格的UIAlertController
1、当UIAlertAction不大于2个时,显示如前两个图;
2、当UIAlertAction大于2个时,显示如后两个图。
注:在苹果上,Cancel按钮在左边/最底部,其他的按添加顺序。

添加文本输入框
1、文本输入框只能添加到Alert的风格中,ActionSheet是不允许的;
2、UIAlertController具有只读属性的textFields数组,需要可直接按自己需要的顺序添加;
3、添加方式是使用block,参数是UITextField;
4、添加UITextField监听方法和实现方法。本回答被提问者采纳
相似回答