【问题标题】:Draw a UIView in greyscale?以灰度绘制 UIView?
【发布时间】:2012-06-01 11:03:39
【问题描述】:

有没有办法以灰度绘制给定的 UIView(及其子视图)?

我正在尝试获取视图层次结构并使其看起来被禁用而不覆盖图像或切换用于绘制层次结构中每个 UIView 的图像。

【问题讨论】:

标签: ios uiview filter grayscale


【解决方案1】:

将 CALayer 添加到您的 UIView,并将 compositingFilter 设置为 colorBlendMode:

let grayLayer = CALayer()
grayLayer.frame = bounds
grayLayer.compositingFilter = "colorBlendMode"
grayLayer.backgroundColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0).cgColor
layer.addSublayer(grayLayer)

【讨论】:

    【解决方案2】:

    当我想禁用视图时,我通常只设置userInteractionEnabled = NOalpha = .5(或其他一些

    【讨论】:

      【解决方案3】:

      您不能以灰度绘制 UIView,但您可以在整个事物的顶部放置一个半透明的 UIView 层以显示灰色的行为。

      检查this

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-12-20
        • 1970-01-01
        • 2015-04-22
        • 1970-01-01
        • 2016-06-16
        • 2019-05-09
        • 1970-01-01
        相关资源
        最近更新 更多