Re: Reverse-engineering Apple's two-tinted gradient NSViews
Re: Reverse-engineering Apple's two-tinted gradient NSViews
- Subject: Re: Reverse-engineering Apple's two-tinted gradient NSViews
- From: Corbin Dunn <email@hidden>
- Date: Thu, 22 Jan 2009 13:47:42 -0800
- (void)drawRect:(NSRect)rect {
// Drawing code here.
NSArray *_colorArray = [NSArray arrayWithObjects:
[NSColor colorWithDeviceRed:0.9843 green:
0.9843 blue:0.9843 alpha:1.0],
[NSColor colorWithDeviceRed:0.9608 green:
0.9608 blue:0.9608 alpha:1.0],
[NSColor colorWithDeviceRed:0.8824 green:
0.8824 blue:0.8824 alpha:1.0],
nil];
NSGradient *_gradient = [[NSGradient alloc]
initWithColors:_colorArray];
[_gradient drawInRect:rect angle:90];
[_gradient release];
}
No one else pointed it out, and it is good practice to understand what
is wrong with your code.
'rect' in drawRect: is the dirty rect, which may or may the entire
bounds. For a gradient, you can't refill just the dirty rect.
Therefore, you must use self.bounds. Brandon's example shows this.
corbin
_______________________________________________
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