【问题标题】:White "outer border" appears after changing UITextField colours in UIAlertController在 UIAlertController 中更改 UITextField 颜色后出现白色“外边框”
【发布时间】:2018-07-01 20:09:35
【问题描述】:

在成功修改我的 UIAlertController 的颜色后,我希望对同一个 UIAlertController 中的 UITextField 执行相同的操作。但是,UITextField 周围会出现一个白色的“外边框”,我设置的边框颜色在该“外边框”内可见。

我想要的是白色“外边框”清晰/与 UIAlertController 视图背景颜色相同。

我当前的代码:

addAlert.addTextField(configurationHandler: { (textField) -> Void in
            textField.placeholder = "ABC 123"
            textField.textAlignment = .left
            textField.backgroundColor = Theme.current.barColor
            textField.textColor = Theme.current.titleColor
            textField.attributedPlaceholder = NSAttributedString(string: "ABC 123", attributes: [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 14, weight: .regular), NSAttributedStringKey.foregroundColor : Theme.current.subTitleColor])
            textField.layer.borderWidth = 1.0
            textField.layer.borderColor = Theme.current.subTitleColor.cgColor
            textField.layer.backgroundColor = Theme.current.barColor.cgColor
        })

UIAlertController 的屏幕截图:

提前谢谢你!

【问题讨论】:

  • 我建议使用您自己的警报视图,而不是尝试自定义 UIAlertController。它不是为定制而完成的。

标签: ios swift uitextfield uikit uialertcontroller


【解决方案1】:

在出现警报后,我可以通过运行此代码来移除白色的“外边框”:

for textField in addAlert.textFields! {
    let container = textField.superview
    let effectView = container?.superview?.subviews[0]

    if (effectView as? UIVisualEffectView) != nil {
        container?.backgroundColor = .clear
        effectView?.removeFromSuperview()
    }
}

这是 Rory's answer 到另一个问题的 Swift 转换

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多