• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Deciding whether text should be black or white for a given background color
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Deciding whether text should be black or white for a given background color (From: Keith Blount <email@hidden>)

  • Prev by Date: [Solved] Re: Synchronizing Thread Execution
  • Next by Date: Re: Synchronizing Thread Execution
  • Previous by thread: Re: Deciding whether text should be black or white for a given background color
  • Next by thread: Re: Deciding whether text should be black or white for a given background color
  • Index(es):
    • Date
    • Thread