Swift_UIAlertController(提示框、警告框)

三种状态 常规(default)、取消(cancel)以及警示(destructive)

1,在中间有点击方法

        let alertVC = UIAlertController(title: "提示", message: "我是提示框", preferredStyle: UIAlertControllerStyle.Alert)
        let acSure = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive) { (UIAlertAction) -> Void in
            print("click Sure")
        }
        let acCancel = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
            print("click Cancel")
        }
        alertVC.addAction(acSure)
        alertVC.addAction(acCancel)
        self.presentViewController(alertVC, animated: true, completion: nil)

2,在中间无点击方法

        let alertController = UIAlertController(title: "提示", message: "我是提示框",preferredStyle: .Alert)
        let cancelAction1 = UIAlertAction(title: "确定", style: .Destructive, handler: nil)
        let cancelAction2 = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
        alertController.addAction(cancelAction1)
        alertController.addAction(cancelAction2)
        self.presentViewController(alertController, animated: true, completion: nil)
        
中间.png

3,在底下有点击方法

        let alertVC = UIAlertController(title: "提示", message: "我是提示框", preferredStyle: UIAlertControllerStyle.ActionSheet)
        let acSure = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive) { (UIAlertAction) -> Void in
            print("click Sure")
        }
        let acCancel = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (UIAlertAction) -> Void in
            print("click Cancel")
        }
        alertVC.addAction(acSure)
        alertVC.addAction(acCancel)
        self.presentViewController(alertVC, animated: true, completion: nil)

4,在底下无点击方法

        let alertController = UIAlertController(title: "提示", message: "我是提示框",preferredStyle: .ActionSheet)
        let cancelAction1 = UIAlertAction(title: "确定", style: .Default, handler: nil)
        let cancelAction2 = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
        alertController.addAction(cancelAction1)
        alertController.addAction(cancelAction2)
        self.presentViewController(alertController, animated: true, completion: nil)
底下.png
UIAlertView(title: "提示", message:"", delegate: nil, cancelButtonTitle: "确定").show()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用了两个星期时间断断续续读完iOS的guidelines英文原版,原文是写得有点啰嗦,所以精选了以下觉得比较重要的...
    Alan的UX笔记阅读 2,237评论 1 17
  • iOS 8的新特性之一就是让接口更有适应性、更灵活,因此许多视图控制器的实现方式发生了巨大的变化。全新的UIPre...
    Tank丶Farmer阅读 2,116评论 2 4
  • 偏见往往都是由于不了解并止步于不了解而来,要赶走偏见,就是在了解之前不轻易下判断。 没有调查就没有发言权。 旅行不...
    唐可竹阅读 337评论 0 0
  • 昨夜的梦 蓦然将我惊醒 惊起我记忆深处 遗忘的你 耳边响起熟悉的旋律 “突然好想你” 唤醒我 和你那段 路人甲...
    旅翼阅读 275评论 0 0
  • https://gold.xitu.io/entry/589c173b8d6d81006c7e9f70 【Jav...
    靖兰亭阅读 607评论 0 50