【问题标题】:Change CALayer color in sync with UIView tintColor when a UIViewController presents a popover当 UIViewController 显示弹出框时,更改 CALayer 颜色与 UIView tintColor 同步
【发布时间】:2020-07-28 08:30:47
【问题描述】:

在 iOS 中,当 UIViewController 呈现一个弹出框时,其视图的 tintColor 将变为黑白颜色(这样,按钮看起来弹出框可见时不可点击)。当弹出框消失时,颜色会变回来。

UIView 有一个子类来保存徽章计数。该视图层的颜色应该与视图的 tintColor 具有相同的颜色。

如何在其父视图中同步子层的tintColor

// draw orange background layer with border  
override func draw(_ rect: CGRect) {
    layer.cornerRadius = rect.height / 2
    layer.borderColor = UIColor.orange.cgColor
    layer.borderWidth = 2
    layer.backgroundColor = UIColor.white.cgColor
    layer.masksToBounds = true
}

默认值:

提交:

【问题讨论】:

    标签: ios swift uiview calayer


    【解决方案1】:

    在自定义 UIView 中覆盖 tintColorDidChange 并将 tintColor 设置为其中的图层 backgroundColor

    override func tintColorDidChange() {
        layer.backgroundColor = tintColor.cgColor
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-19
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多