Re: How to change focus ring color?
Re: How to change focus ring color?
- Subject: Re: How to change focus ring color?
- From: Joel Norvell <email@hidden>
- Date: Fri, 31 Jul 2009 14:54:08 -0700 (PDT)
Alexander,
If you're drawing the focus ring yourself, you can change its color by setting it in the NSGraphicsContext that's active while it's being drawn.
I draw NSView/NSControl focus rings by hand in one of my apps. I've posted the code that does this, below. I'm not changing the color of the focus ring, but easily could by setting some color other than keyboardFocusIndicatorColor.
My approach is fairly heavy-handed. I'm not suggesting that you adopt it, just that it's possible.
You didn't say what objects you are drawing, so I should add this caveat: I'm not sure what variations, if any, would be induced by generalizing my approach to NSCell objects.
Sincerely,
Joel
- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
if ([self focus])
{
[self drawFocusRing];
[NSGraphicsContext saveGraphicsState];
NSRect whiteOutRect = NSInsetRect([self bounds], 2, 2);
[self whiteOutInterior:whiteOutRect];
[NSGraphicsContext restoreGraphicsState];
}
}
- (void) drawFocusRing
{
if ([self focus])
{
[NSGraphicsContext saveGraphicsState];
[self whiteOutFocusRegion:[self bounds]]; // whiteOutFocusRegion
[[NSColor keyboardFocusIndicatorColor] set];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect:[self bounds]] fill];
[NSGraphicsContext restoreGraphicsState];
[self setFocusRingDrawn:YES];
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden