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

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

Reply via email to