星空网 > 软件开发 > 操作系统

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

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之后新的方式,之前的已经弃用)

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

免费换货:https://www.goluckyvip.com/tag/6882.html
秒杀倒计时:https://www.goluckyvip.com/tag/6883.html
新消息:https://www.goluckyvip.com/tag/6884.html
团队联系方式:https://www.goluckyvip.com/tag/6885.html
邮箱汇:https://www.goluckyvip.com/tag/6886.html
广告投放攻略:https://www.goluckyvip.com/tag/6887.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
南美旅游报价(探索南美洲的旅行费用):https://www.vstour.cn/a/411234.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流