问题
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