ios中UIAlertController的使用创建对话框、操作表

创建一个对话框、操作表

//创建一个UIAlertController 对话框 并指定标题和内容 preferredStyle:指定样式(nil就是为默认样式 也就是操作表的样式)
UIAlertController *uiAlertController = 
[UIAlertController alertControllerWithTitle:@"提示框" message:@"what???"preferredStyle:UIAlertActionStyleCancel];
    
//创建一个操作表 或者用这样的方式创建:使用上方的初始化方式 且参数都设为nil)
IAlertController *sheetController =[[UIAlertController alloc]init];

style:


UIAlertActionStyleDefault:默认样式(蓝色字体)


UIAlertActionStyleCancel:取消样式


创建按钮并添加到UIAlertController

//创建取消按钮 指定按钮文本、按钮样式和点击后的操作 
    UIAlertAction *noAction =
	[UIAlertAction actionWithTitle:@"No" 
	style:UIAlertActionStyleDestructive 
	handler:^(UIAlertAction * action) {
        NSLog(@"用户取消操作");
    }];
    
    
    UIAlertAction *yesAction =
	[UIAlertAction actionWithTitle:@"Yes" 
	style:UIAlertActionStyleDestructive 
	handler:^(UIAlertAction * action) {
        NSLog(@"确定");
    }];
    
    //将创建的两个按钮添加到对话框
    [uiAlertController addAction:noAction];
    [uiAlertController addAction:yesAction];

按钮多一种style: UIAlertActionStyleDestructive: 警告样式(红色字体)

显示对话框

 [self presentViewController:uiAlertController animated:true completion:nil];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值