是否有混合模式或我可以为UIControl设置的其他东西,以便我可以看到它下面的图层?

问题描述 投票:1回答:1

我在视图中添加了各种UIControl。我想在Photoshop中使用像混合模式一样的渐变显示图像。

UIControls untouched

UIControls with gradient underneath it, showing through

这里我使用了亮度混合模式。我希望有类似的东西,我可以在Swift的图层上访问。

ios swift blending uicontrol
1个回答
2
投票

我想出了如何使用compositingFilter属性执行此操作。我尝试了这个,但是倒退了。它必须用在图像上,该图像应该是UIControls之上的一层:

    let image: UIImage = UIImage(named: "testBGGradient.png")!
    let bgImage = UIImageView(image: image)
    bgImage.frame = CGRect(x:0, y:topBarYPos + topBarHeight + topMargin, width:UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)
    guard let str = dbBlendStr else { return }
    bgImage.layer.compositingFilter = "darkenBlendMode"

    self.view.addSubview(bgImage)

有很多compositingFilters。使用适合你的那些:https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP30000136-SW71

您可以使用过滤器名称删除“CI”并从小写字母开始。这里有一个简单的列表可供选择:

additionCompositing

colorBlendMode

colorBurnBlendMode

颜色减淡混合模式

darkenBlendMode

differenceBlendMode

divideBlendMode

排除混合模式

hardLightBlendMode

hueBlendMode

lightenBlendMode

linearBurnBlendMode

线性道奇混合模式

光度混合模式

maximumCompositing

minimumCompositing

乘以混合模式

multiplyCompositing

叠加混合模式

© www.soinside.com 2019 - 2024. All rights reserved.