1

我正在使用 swift 2.2 开发一个应用程序,在我的应用程序中,当用户点击该按钮时,我有一个按钮,警报视图将出现,其中包含垂直的四个按钮,一切正常,但警报视图出现在视图控制器的底部如何显示在视图控制器的中心。

注意:我不想显示任何标题和消息,我只需要显示四个按钮。

如果我使用这个:

let alert = UIAlertController(title: " ", message: "select colors", preferredStyle: UIAlertControllerStyle.Alert)

它有助于显示在视图控制器的中心,但没有标题和消息,它看起来并不好,所以我使用了以下代码

代码:

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)
4

4 回答 4

1

只需将标题和消息设置为零。我在swift 3中对其进行了测试。

let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.alert)
于 2016-11-21T08:23:00.173 回答
0

在您展示您的alert,

alert.popoverPresentationController!.sourceView = self.view
alert.popoverPresentationController!.sourceRect = self.view.bounds
于 2016-11-21T08:14:20.543 回答
0

你可以这样做:

let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
于 2016-11-21T08:12:12.607 回答
0

它会自动出现在其属性的中心 :) 但您真正想要的是什么?

于 2016-11-21T08:12:56.527 回答