3

enter image description here

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?

James Anderson
  • 556
  • 3
  • 16
  • 41
  • 2
    Checkout 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 Answers1

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.

Community
  • 1
  • 1
InkGolem
  • 2,662
  • 1
  • 15
  • 22