iOS8新特性之---- UIAlertController解析

UIAlertController继承自 UIViewController, 也是一个控制器


 以前使用按钮(UIAlertView和UIActionSheet)
 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:
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值