Because the UIImageView in the background is very light, you can't see the text in the foreground on top of the UIVisualEffectView. I want to detect whether the background is light or not and if so, change the text colour to something darker. How can I do this?
Asked
Active
Viewed 497 times
3
-
2Checkout UIVibrancyEffect (https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIVibrancyEffect/index.html). It's intended to be used on top of a blur effect to make the test stand out more by dynamically changing the text color based on the background. In particular, this is a great answer related to this: http://stackoverflow.com/a/24225231/482255 – Msencenb Feb 11 '15 at 21:00
1 Answers
2
To detect the dominant color of a UIView it takes two steps. First is to capture the image data of the view as described here: How to capture UIView to UIImage without loss of quality on retina display
Second is to determine what the dominant color of the view is as described here: How does the algorithm to color the song list in iTunes 11 work?
And then make your adjustments based on the result.
Personally, I would simply use a dark text color for the light blur. Or continue with the light text and use the dark blur effect. Or set a tint color on a navigation bar.