我正在开发一个应用程序使用swift 2.2,在我的应用程序我有一个按钮,当用户点击该按钮时将出现警报视图,其中包含四个按钮在垂直一切工作正常,但警报视图出现在视图控制器的底部如何显示在视图控制器的中心。如何使警报视图出现在视图控制器的中心使用swift 2.2
注:我不想显示任何标题和消息,只需要显示四个按钮。
如果我用这一个:
let alert = UIAlertController(title: " ", message: "select colors", preferredStyle: UIAlertControllerStyle.Alert)
它有助于在视图控制器的中心,但没有title,消息显示它看起来并不好,所以我用下面的代码
代码:
let alert = UIAlertController()
alert.addAction(UIAlertAction(title: "Red Color", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "Blue Color", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "Green Color", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "Yellow Color", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
谢谢你,这工作得很好 –