首页 > 编程语言 > 详细

Swift之使用UIAlertController实现UIActionsheet

时间:2015-07-11 09:15:28      阅读:224      评论:0      收藏:0      [点我收藏+]

在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翻译并以博客形式写出来。


Swift之使用UIAlertController实现UIActionsheet

原文:http://blog.csdn.net/lpf123go/article/details/46835217

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