2016-11-21 47 views
0

我正在开发一个应用程序使用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) 

回答

0

只需设置标题和消息为零。我在迅速3.

let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.alert) 
+0

谢谢你,这工作得很好 –

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) 
+0

测试它我不想显示任何标题和消息 –

+0

让alertView = UNAlertView(标题: “”,消息:““) alertView.messageAlignment = NSTextAlignment.Center alertView。 buttonAlignment = UNButtonAlignment.Horizo​​ntal alertView.addButton( “红颜色”,动作:{ }) alertView.addButton( “蓝色”,动作:{ }) alertView.show() –

+0

你可以尝试用上面的代码... –

0

它会自动进入中心的属性:)但你真正想要什么?

+0

我会检查并回复回复....谢谢 –

+0

https://pastebin.ubuntu.com/23260075/ – KhanShaheb

+0

没有它出现在视图控制器的底部 –

0

添加以下代码行您出示您的alert之前,

alert.popoverPresentationController!.sourceView = self.view 
    alert.popoverPresentationController!.sourceRect = self.view.bounds 
+1

它显示我意外发现的错误致命错误无解包装可选值 –

+0

无法加载任何客观的C类信息 –

相关问题