Swift之使用UIAlertController实现UIActionsheet
来源:互联网 发布:知乎 无色方糖 编辑:程序博客网 时间:2024/05/21 15:44
在iOS8的UIActionSheet被废弃,我们在实现UIActionsheet时会选择用UIAlertController来实现。本篇博文将会实现UIAlertView实现UIactionSheet效果。
具体步骤:
1、创建一个ActionSheet类型的UIAlertController;
2、为1中创建的UIAlertController创建两个方法;本例中创建一个添加方法:addAction()和一个删除方法deleteAction();
3、创建一个取消方法,参数style类型为Cancel;
4、将2和3步骤中创建的方法添加给1中创建的UIAlertController;
5、将1中创建的UIAlertContrller使用模态视图推出。
具体代码实现如下:
</pre><pre name="code" class="html">@IBAction func showActionSheet(sender: AnyObject) { println("show action sheet") let optionMenu = UIAlertController(title: nil, message: "选择", preferredStyle: .ActionSheet) let deleteAction = UIAlertAction(title: "删除", style: .Default, handler:{ (alert: UIAlertAction!) -> Void in println("删除") }) let saveAction = UIAlertAction(title: "保存", style: .Default, handler: { (alert: UIAlertAction!) -> Void in println("保存") }) let cancelAction = UIAlertAction(title: "取消", style: .Cancel, handler: { (alert: UIAlertAction!) -> Void in println("取消") }) optionMenu.addAction(saveAction) optionMenu.addAction(deleteAction) optionMenu.addAction(cancelAction) self.presentViewController(optionMenu, animated: true, completion: nil) }
效果如下:
注:最近在结合国外swift开发网站学习swift,坚持每天将自己学的swift翻译并以博客形式写出来。
0 0
- Swift之使用UIAlertController实现UIActionsheet
- Swift 之 UIACtionSheet
- UIAlertController的使用(Swift)
- swift 的 UIAlertController使用
- Swift基础(二十二)UIAlertView,UIActionSheet,UIAlertController
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- IOS开发之 ---- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
- <swift学习之路> UIAlertController的简单使用
- swift中UIActionSheet的使用
- swift中UIActionSheet的使用
- swift中UIActionSheet的使用
- Swift基础之对话框UIAlertController
- Swift中UIAlertController的使用
- 关于UIAlertController的使用(swift)
- Swift - UIAlertController的简单使用
- Swift-->UIAlertController(对话框)的使用
- Swift 3.0 UIAlertController的使用
- VMware虚拟机下 Redhat上网
- 如何在discuz帖子中插入视频
- Subsets
- 任正非转型狠招:如何让宝马追上特斯拉?
- 欢迎使用CSDN-markdown编辑器
- Swift之使用UIAlertController实现UIActionsheet
- atitit.微信支付的教程文档 attilax总结
- Android_Touch事件的分发和消费机制
- IOS--UI--LessonNavigationController
- COCOS2D-X 学习
- 给儿子讲美国独立战争
- 42.翻转单词顺序VS左旋转字符串
- Atitit. 脚本语言的断点单步调试的设计与实现 attialx 总结 php 参照java
- cairo绘图png,pdf,svg