UIAlertController继承自 UIViewController, 也是一个控制器
UIAlertController 不管是要用 UIAlertView 还是 UIActionSheet 方式展示,都要以 title 和 message 参数来初始化.UIAlertView 会在当前显示的 view controller 中心以模态形式出现,UIActionSheet 则会在底部滑出。UIAlertView 可以同时有按钮和输入框,UIActionSheet 仅支持按钮。
新的方式并没有把所有的 alert 按钮配置都放在初始化函数中,而是引入了一个新类 UIAlertAction 的对象,在初始化之后可以进行配置。这种形式的 API 重构让对按钮数量、类型、顺序方便有了更大的控制。同时也弃用了 UIAlertView 和 UIActionSheet 使用的delegate 这种方式,而是采用更简便的完成时回调。
#import "LoveViewController.h"
#import "NBViewController.h"
@interface LoveViewController ()<UITextFieldDelegate>
// 账号
@property (nonatomic,copy) NSString *name;
// 密码
@property (nonatomic,copy) NSString *passWord;
// 用来显示数据
@property (nonatomic,retain) UILabel *lable;
// 分段控件
@property (nonatomic,retain) UISegmentedControl *segment;
// 创建UIAlertControlle控件
@property (nonatomic,retain) UIAlertController *alertController;
@end
@implementation LoveViewController
// 释放
- (void)dealloc{
[_alertController release];
[_segment release];
[_lable release];
[_passWord release];
[_name release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
#pragma mark -------UIActionSheet------
// [self createSheet];
#pragma mark -------UIAlertView------
// [self createAlertView];
#pragma mark -------加载控件--------
[self setUp];
// 创建分段控件
// 创建数组
NSArray *itemArray = @[@"UCStyleAlert",@"UCStyleActionSheet"];
self.segment = [[UISegmentedControl alloc]initWithItems:itemArray];
self.segment.frame = CGRectMake(10, 30, 300, 40);
// 默认选中项
[self.segment setSelectedSegmentIndex:1];
// 修改字体大小
NSDictionary *dic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor whiteColor]};
[self.segment setTitleTextAttributes:dic forState:(UIControlStateNormal)];
// 设置宽度
[self.segment setWidth:180 forSegmentAtIndex:1];
[self.view addSubview:self.segment];
[self.segment addTarget:self action:@selector(segmentCR:) forControlEvents: