美文网首页
Swift_UIAlertController(提示框、警告框)

Swift_UIAlertController(提示框、警告框)

作者: _杜兜兜_ | 来源:发表于2016-10-10 11:12 被阅读3837次

三种状态 常规(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()

相关文章

网友评论

      本文标题:Swift_UIAlertController(提示框、警告框)

      本文链接:https://www.haomeiwen.com/subject/jjgmyttx.html