Works splendidly, thank you! I just check if my color is darker than 0.7 and 
use highlightWithLevel otherwise use shadowWithLevel.

Martin


On 15, Sep, 2012, at 11:14 AM, Markus Spoettl <ms_li...@shiftoption.com> wrote:

> On 9/15/12 10:52 AM, Martin Hewitson wrote:
>> I'm not sure what the correct terminology is here. I have a text editor app
>> and the user can set the background color of the editor. The user can also
>> set the line length for wrapping. Past that length, I have been drawing a
>> shaded rect (in the text view subclass' -drawViewBackgroundInRect:). For the
>> shaded rect, I've been using NSColor's shadowWithLevel:. This works fine for
>> most colors, but obviously not for a black background.  I suppose in some
>> cases I could highlightWithLevel and in others shadowWithLevel, but I don't
>> know how to distinguish between these cases. Is there something else I could
>> do to get a reasonable contrasting color?
> 
> You can create a monoChrome color from your background color and ask for its 
> -whiteComponent which will tell you how light it is. I use a category on 
> NSColor like this:
> 
> @implementation NSColor (lightness)
> 
> - (BOOL)isDarkerThan:(float)lightness
> {
>  NSColor *monoColor = [self 
> colorUsingColorSpaceName:@"NSCalibratedWhiteColorSpace"];
>  return ([monoColor whiteComponent] < lightness);
> }
> 
> @end
> 
> You can then query your color using a value between 0.0 and 1.0 and choose 
> the appropriate color for your shadow.
> 
> Regards
> Markus
> -- 
> __________________________________________
> Markus Spoettl
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please 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:
> https://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de
> 
> This email sent to martin.hewit...@aei.mpg.de







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to