UIAlertController

UIAlertController相关

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建两个button
    [self createTwoButton];
    
    //创建一个警告框
    [self createOneAlertCon];
    
    //创建一个操作表
    [self createOneSheetCon];
    

}

-(void)createTwoButton{
    CGRect screen = [[UIScreen mainScreen] bounds];
    
    UIButton* buttonAlertView = [UIButton buttonWithType:UIButtonTypeSystem];
    [buttonAlertView setTitle:@"警告框" forState:UIControlStateNormal];
    
    CGFloat buttonAlertViewWidth = 100;
    CGFloat buttonAlertViewHeight = 30;
    CGFloat buttonAlertViewTopView = 130;
    
    buttonAlertView.frame = CGRectMake((screen.size.width - buttonAlertViewWidth)/2 , buttonAlertViewTopView, buttonAlertViewWidth, buttonAlertViewHeight);
    //指定事件处理方法
    [buttonAlertView addTarget:self action:@selector(createOneAlertCon) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview:buttonAlertView];
    
    
    UIButton* buttonActionSheet = [UIButton buttonWithType:UIButtonTypeSystem];
    [buttonActionSheet setTitle:@"操作表" forState:UIControlStateNormal];
    
    CGFloat buttonActionSheetWidth = 100;
    CGFloat buttonActionSheetHeight = 30;
    CGFloat buttonActionSheetTopView = 260;
    
    buttonActionSheet.frame = CGRectMake((screen.size.width - buttonActionSheetWidth)/2 , buttonActionSheetTopView, buttonActionSheetWidth, buttonActionSheetHeight);
    //指定事件处理方法
    [buttonActionSheet addTarget:self action:@selector(createOneSheetCon) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview:buttonActionSheet];
}

#pragma mark - 创建一个警告框
-(void)createOneAlertCon{
    
    UIAlertController* alertController  = [UIAlertController alertControllerWithTitle:@"Alert" message: @"Alert text goes here" preferredStyle:UIAlertControllerStyleAlert];
    
//    UIAlertControllerStyleActionSheet = 0,//默认类型  操作表
//    UIAlertControllerStyleAlert//警告框

    
    UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"Tap No Button");
    }];
    
    UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"Tap Yes Button");
    }];
    
    UIAlertAction* otherAction = [UIAlertAction actionWithTitle:@"other" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"Tap other Button");
    }];
    [alertController addAction:noAction];
    [alertController addAction:yesAction];
//    [alertController addAction:otherAction];
    
    //显示
    [self presentViewController:alertController animated:TRUE completion:nil];

}

#pragma mark - 创建一个操作表
-(void)createOneSheetCon{
    UIAlertController* actionSheetController = [[UIAlertController alloc] init];//默认创建的是UIAlertControllerStyleActionSheet类型
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"Tap 取消 Button");
    }];
    
    UIAlertAction* destructiveAction = [UIAlertAction actionWithTitle:@"破坏性按钮" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        NSLog(@"Tap 破坏性按钮 Button");
    }];
    
    UIAlertAction* otherAction = [UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSLog(@"Tap 新浪微博 Button");
    }];
    
    [actionSheetController addAction:cancelAction];
    [actionSheetController addAction:destructiveAction];
    [actionSheetController addAction:otherAction];
    
    //显示
    [self presentViewController:actionSheetController animated:TRUE completion:nil];
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值