Render all UIViews below in grayscale
Asked Answered
M

2

8

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!

Multipartite answered 3/3, 2016 at 9:48 Comment(2)
Had you think of set background color for your view and alpha to make it look slightly transparentCoriss
Take a screenshot from your views, convert the image to gray scale, put it there as UIImageView. The only viable solution.Shred
M
7

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!

enter image description here

Multipartite answered 6/3, 2016 at 23:54 Comment(1)
This is a noob question probably, but how to use it in Obj-C ?Baptize
L
0

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
Landry answered 2/9, 2022 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.