【发布时间】:2015-10-21 16:16:42
【问题描述】:
这是一个奇怪的问题。我正在使用以下代码制作 UIAlertController:
let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: UIAlertControllerStyle.ActionSheet)
let action = UIAlertAction(title: "Action 1", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
let action2 = UIAlertAction(title: "Action 2", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
optionMenu.addAction(cancelAction)
optionMenu.addAction(action)
optionMenu.addAction(action2)
self.presentViewController(optionMenu, animated: true, completion: nil)
这就是它在屏幕上的样子。选项很暗淡(我相信拉入或受到后视的影响)。
我能够添加此代码以使其成为纯白色,但分离的美感消失了。
let subview = optionMenu.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.whiteColor()
alertContentView.layer.cornerRadius = 2
它看起来像这样:Non-dimmed, but not quite right
关于如何不让背景影响 UIAlertController 中的选项的任何想法?
我将此 UIAlertController 添加到具有白色背景的页面中,看起来应该如此。
谢谢!
【问题讨论】:
-
您可以选择变暗的行吗?您是否在任何地方使用 UIAppearance 对任何元素的外观进行了全局更改?
-
嗨@shim 我可以选择行。我相信下面的 matt 是对的,但我仍然想知道如何使它们不透明,并且仍然保留它们的原始形状。
-
我也有同样的问题;作为旁注,您可以简单地使用 optionMenu.view.backgroundColor = UIColor.whiteColor() 来获取您的第二张图像,无需在视图中挖掘。它仍然覆盖默认形状,我仍然不确定如何保留它们并转到不透明的白色。
标签: ios swift uialertcontroller