iOS9 提示框的使用
2016-01-18 15:38
501 查看
在从iOS8到iOS9的升级过程中,弹出提示框的方式有了很大的改变,在Xcode7 ,iOS9.1的SDK中,已经明确提示不再推荐使用UIAlertView,而只能使用UIAlertController,我们通过代码来演示一下。
UIImagePickerController * picker = [[UIImagePickerController
alloc] init];
picker.delegate =
self;
//初始化提示框;
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle: UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction
actionWithTitle:@"拍照"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType =
UIImagePickerControllerSourceTypeCamera;
}else{
NSLog(@"模拟器无法打开相机");
}
[self
presentViewController:picker
animated:YES
completion:nil];
}]];
[alert addAction:[UIAlertAction
actionWithTitle:@"相册"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
picker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
[self
presentViewController:picker
animated:YES
completion:nil];
}]];
[alert addAction:[UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
}]];
//弹出提示框;
[self
presentViewController:alert
animated:true
completion:nil];
//初始化提示框;
UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:
UIAlertControllerStyleAlert];
UIImagePickerController * picker = [[UIImagePickerController
alloc] init];
picker.delegate =
self;
//初始化提示框;
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle: UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction
actionWithTitle:@"拍照"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType =
UIImagePickerControllerSourceTypeCamera;
}else{
NSLog(@"模拟器无法打开相机");
}
[self
presentViewController:picker
animated:YES
completion:nil];
}]];
[alert addAction:[UIAlertAction
actionWithTitle:@"相册"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
picker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
[self
presentViewController:picker
animated:YES
completion:nil];
}]];
[alert addAction:[UIAlertAction
actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *
_Nonnull action) {
//点击按钮的响应事件;
}]];
//弹出提示框;
[self
presentViewController:alert
animated:true
completion:nil];
//初始化提示框;
UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:
UIAlertControllerStyleAlert];
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 在ASP.NET使用JavaScript显示信息提示窗口实现原理及代码
- jQuery实现信息提示框(带有圆角框与动画)效果
- jquery插件珍藏(图片局部放大/信息提示框)
- javascript实现确定和取消提示框效果
- js右下角弹出提示框示例代码
- JS组件Bootstrap实现弹出框和提示框效果代码
- jquery悬浮提示框完整实例
- 关闭浏览器窗口弹出提示框并且可以控制其失效
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法