Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Figuring out the text color based on background view color iOS

I have these Views on which I add UILabels as text, The Views can have a background color that is dynamic and cannot be chosen,

Based on that I need to figure out the font color from only a set of three choices - two black or white or dark grey.

For example on a dark red background, a white font would be more suitable than black, while on a light yellow, perhaps a dark grey or black would be readable,

is there any index i could check from the background UIColor to see the illuminance?

like image 328
user134611 Avatar asked Mar 27 '12 18:03

user134611


People also ask

How do I find out what color my text is?

Select the text you're interested in. Right click on the text and choose Font from the context menu (or just hit ctrl-D) Click the down arrow to the right of the Font color setting, then click More Colors. Click the Custom tab, and you'll see the RGB value of the colour.

Which is the Coloured background behind the text?

Detailed Solution. The correct answer is Shading. For the color background of the text in a document, select the text and choose a color as per requirement.

How do you color text on IOS?

Change the color of text If you don't see text controls, tap Cell or Text. Tap Text Color, then choose one of the following: A color or gradient designed to go with the template: Tap Preset, swipe left or right to see all the choices, then tap a color.

How do I change the background color on my iPhone messages?

Once installed, open the Messages app start a new iMessage. In the menu above the keyboard and select "Color". Select "Type Custom Message", and type your message in the bubble. From the color bubble (highlighed below), select from a range of colors to change text background color on iPhone.


1 Answers

Take a look at my UIColor category and the blackOrWhiteContrastingColor method. This will tell you what will look better out of black or white. You could extend that to support dark grey as well.

Basically the way it works is to look at the luminosity difference between the target colour and black, and then between the target colour and white. It then chooses the biggest luminosity difference.

like image 198
mattjgalloway Avatar answered Oct 20 '22 00:10

mattjgalloway