关于iOS中的弹出窗口----UIAlertController

iOS中的弹出窗口分为UIAlertView和UIActionSheet这两种,其中前者类似于Android中的dialog,在屏幕中间弹出一个窗口;后者为在屏幕下方弹出的窗体。

在iOS8以后,两者由UIAlertController统一实现:

UIAlertView的实现--

    UIAlertController* ui=[UIAlertController alertControllerWithTitle:@"title" message:@"helloWorld" preferredStyle:UIAlertControllerStyleAlert];

----实例化一个UIAlertController对象,在这里指定样式为UIAlertView。

    UIAlertAction* cancel=[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:nil

    ];

----为该提示框添加第二个选项

    UIAlertAction* other=[UIAlertAction actionWithTitle:@"qitade" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){

    }];

----为该提示框添加第三个选项

    UIAlertAction* other1=[UIAlertAction actionWithTitle:@"qitade" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){

    }];

-----添加单个提示框的选项(字体较大的红色提示)

    UIAlertAction* reset=[UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:nil];

    //[ui addAction:reset];

    [ui addAction:cancel];

    [ui addAction:other];

    [ui addAction:other1];

    [self presentViewController:ui animated:YES completion:nil];

--------当添加两个时候,会左右排列,超出后会上下排列

--------实现一个输入用户名和密码界面的dialog

UIAlertController* ui1=[UIAlertController alertControllerWithTitle:@"t提示框" message:@"请输入" preferredStyle:UIAlertControllerStyleAlert];

    [ui1 addTextFieldWithConfigurationHandler:^(UITextField *text){

        text.placeholder=@"用户名";//这个相当于Android的edittext的提示语

    }];

    [ui1 addTextFieldWithConfigurationHandler:^(UITextField* text1){

    text1.placeholder=@"密码";

        text1.secureTextEntry=YES;

    }];

    [self presentViewController:ui1 animated:YES completion:nil];



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值