Re: NSShadow not working as expected
Re: NSShadow not working as expected
- Subject: Re: NSShadow not working as expected
- From: Ricky Sharp <email@hidden>
- Date: Sat, 30 Jun 2007 20:04:56 -0500
On Jun 30, 2007, at 3:10 PM, Ken Tozier wrote:
I'm trying to apply an NSShadow inside the drawRect method of a
custom view and can't get it to appear. Here's the code
- (void) drawRect:(NSRect) inRect
{
NSShadow *shadow = [[[NSShadow alloc] init] autorelease];
[shadow setShadowOffset: NSMakeSize(2, -2)];
[shadow setShadowBlurRadius: 3];
[shadow set];
[backgroundColor set];
NSRectFillUsingOperation(inRect, NSCompositeSourceOver);
if (selected)
{
[[NSColor keyboardFocusIndicatorColor] set];
NSFrameRectWithWidth(inRect, 2);
}
}
The strange thing is, if selected = YES, the shadow draws inside
the focus ring but if selected = NO, no shadow is drawn at all.
I want the shadow to appear outside the rectangle specified by
"inRect." Anyone see what I'm doing wrong?
inRect will typically be your view's entire bounds. Thus, in that
case, you'll be filling the entire view with a single color
(background color) and the applied shadow will be completely outside
your view's bounds (i.e. clipped).
Shadows only work well when they are not clipped. So, you'll want to
inset your drawing rect a bit (and, you probably should change your
code to use the view's actual bounds).
Finally, I'll assume that you do not want the shadow to be applied to
the focus ring. You'll want to thus wrap your code a bit with save/
restore graphics state calls.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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