Reputation: 1864
In my app, I would like to present a transparent UIView (or layer) which acts as a color filter. So, when this view is presented everything below, it is shown in grayscale.
Is this possible, and if yes how would you go about doing this? I know how to render a UIView specifically in grayscale but this is not what I want to achieve.
Thanks!
Upvotes: 8
Views: 3797
Reputation: 19
A lot easier than drawing everything with a lot of code:
You could add this view on top. Layout etc. just as every view.
let view = UIView()
// with alpha components: modify saturation. Without => alpha 1.0 Gray scale
view.backgroundColor = .white
view.layer.compositingFilter = "hueBlendMode"
view.isUserInteractionEnabled = false
Upvotes: 0
Reputation: 1864
As I didn't find any acceptable solution I went and created this myself. You can check it out in my Git repository. It cannot only filter in grayscale but also sepia, etc. Check out the project, its pretty straight forward.
Any contributions to the project are welcome, there is obviously a lot to add and improve!
Upvotes: 7