我正在開發一個應用程序使用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)
謝謝你,這工作得很好 –