Is there a blending mode or something else I can set for UIControls so that I can see a layer beneath it?

最后都变了- 提交于 2019-12-24 10:49:30

问题


I have various UIControls added to my view. I'd like to have an image of a gradient show through it like I can with a like a blending mode in Photoshop.

Here I used the luminance blending mode. I'm hoping there's something similar that I can access on the layer in Swift.


回答1:


I figured out how to do this with the compositingFilter property. I tried this, but had it backwards. It must be used on the image which should be a layer on top of the 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)

There are many compositingFilters. Use the ones right for you found here: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP30000136-SW71

You can use the filter names removing the "CI" and starting with a lower case. Here's an easy list to choose from:

additionCompositing

colorBlendMode

colorBurnBlendMode

colorDodgeBlendMode

darkenBlendMode

differenceBlendMode

divideBlendMode

exclusionBlendMode

hardLightBlendMode

hueBlendMode

lightenBlendMode

linearBurnBlendMode

linearDodgeBlendMode

luminosityBlendMode

maximumCompositing

minimumCompositing

multiplyBlendMode

multiplyCompositing

overlayBlendMode



来源:https://stackoverflow.com/questions/54717378/is-there-a-blending-mode-or-something-else-i-can-set-for-uicontrols-so-that-i-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!