首页 > 移动平台 > 详细

自学iOS开发小功能之三:弹框的两种方式(iOS8.3之后新的方式,之前的已经弃用)

时间:2016-04-24 21:44:34      阅读:257      评论:0      收藏:0      [点我收藏+]

1、弹框出现在屏幕中间位置

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否退出" preferredStyle: UIAlertControllerStyleAlert]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        //点击确认后需要做的事
    }]];
    [self presentViewController:alert animated:YES completion:nil]; //注意一定要写此句,否则不会显示

 

此方法可以添加文本框,输入内容

 [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入名字";
    }];
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入价格";
    }];

 

2、弹框出现在屏幕底部(两种方式的不同点在于代码第一行最后的,底部是UIAlertControllerStyleActionSheet

1 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否退出" preferredStyle: UIAlertControllerStyleActionSheet]; 
2     [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
3     [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
4         //点击确认后需要做的事
5     }]];
6     [self presentViewController:alert animated:YES completion:nil]; //注意一定要写此句

 

自学iOS开发小功能之三:弹框的两种方式(iOS8.3之后新的方式,之前的已经弃用)

原文:http://www.cnblogs.com/hissia/p/5428248.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!