Re: Deciding whether text should be black or white for a given background color
Re: Deciding whether text should be black or white for a given background color
- Subject: Re: Deciding whether text should be black or white for a given background color
- From: Todd Ransom <email@hidden>
- Date: Wed, 6 Dec 2006 10:33:40 -0500
Keith,
I have not actually looked at it but I remember seeing this a while
back.
http://mattgemmell.com/source/
Take a look at NSColor+ContrastingLabelExtensions
Todd Ransom
Return Self Software
http://returnself.com
On Dec 4, 2006, at 12:36 PM, Keith Blount wrote:
Hello,
I have a custom view that draws text on various "cards". Each of
these cards can have any background colour, which is defined by a
fully-customisable label colour assigned by the user.
By default, the text is drawn on these cards in black. However, if
the user wants to use a really dark label colour (eg. dark purple),
this makes the text really difficult to read. Ideally, I would like
the text to be drawn in black for light-coloured backgrounds, and
in white for dark-coloured backgrounds.
The problem is, how do I programmatically decide what is a light-
and what is a dark-coloured background using methods availalbe to
NSColor? Is there a well-known algorithm for deciding this? At
first I thought that if I just checked if the red, green and blue
components of the background colour were 0.5 or above (ie. nearer
white), then I would use black text, and white otherwise. But
obviously, that is silly, as it would fail for colours with two
components very dark and one light (if you see what I mean).
So, my question is, is there a simple way of deciding whether black
or white provides the best contrast for any given NSColor?
Many thanks in advance,
Keith
______________________________________________________________________
______________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden