【问题标题】:Why are the options in my UIAlertController dim and how can I fix it?为什么我的 UIAlertController 中的选项变暗了,我该如何解决?
【发布时间】: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)

这就是它在屏幕上的样子。选项很暗淡(我相信拉入或受到后视的影响)。

Dimmed Options

我能够添加此代码以使其成为纯白色,但分离的美感消失了。

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


【解决方案1】:

这不是错误。没有什么是“变暗的”。警报按钮是半透明的,因此在深色背景上它们会更暗。它们在红色背景上也呈红色,在蓝色背景下呈蓝色;这就是半透明的意思。所有应用程序中的所有操作表都是这样的。这里没有问题。别担心,开心就好。

【讨论】:

  • 即使有些人更喜欢这种外观,也有很多人希望所有按钮都具有相同的颜色/透明度。取消是全白的,所有其他的动作有点灰不是我的设计所要求的......
  • @Tasonir 然后不要使用 UIAlertController。它不会做任何你自己做不到的事情。如果您只使用自定义呈现的视图控制器,您可以随心所欲地
【解决方案2】:

这是我的目标 c 代码。尝试相同的快速对应物:

[alert.view setBackgroundColor:[UIColor whiteColor]];

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-02
    • 2020-09-14
    • 1970-01-01
    • 2019-11-02
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多