• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reverse-engineering Apple's two-tinted gradient NSViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reverse-engineering Apple's two-tinted gradient NSViews


  • Subject: Re: Reverse-engineering Apple's two-tinted gradient NSViews
  • From: Brandon Walkin <email@hidden>
  • Date: Thu, 22 Jan 2009 12:02:15 -0500

The view in question has a 4-stop gradient, with each stop positioned at a particular point, rather than spaced evenly. The view also draws a grey line at the top, so you'll want to reduce the height of the gradient rect by a pixel to leave space for it so you can draw it at some other point in drawRect:.

Here's the relevant code from BWToolkit (http://brandonwalkin.com/bwtoolkit ):

static NSColor *topColor, *middleTopColor, *middleBottomColor, *bottomColor;
static NSGradient *gradient;


+ (void)initialize;
{
topColor = [[NSColor colorWithCalibratedWhite:(253.0f / 255.0f) alpha:1] retain];
middleTopColor = [[NSColor colorWithCalibratedWhite:(242.0f / 255.0f) alpha:1] retain];
middleBottomColor = [[NSColor colorWithCalibratedWhite:(230.0f / 255.0f) alpha:1] retain];
bottomColor = [[NSColor colorWithCalibratedWhite:(230.0f / 255.0f) alpha:1] retain];


    gradient = [[NSGradient alloc] initWithColorsAndLocations:
               topColor, (CGFloat)0.0,
               middleTopColor, (CGFloat)0.45454,
               middleBottomColor, (CGFloat)0.45454,
               bottomColor, (CGFloat)1.0,
               nil];
}

- (void)drawRect:(NSRect)rect
{
    rect = self.bounds;

NSRect gradientRect = NSMakeRect (rect.origin.x,rect.origin.y,rect.size.width,rect.size.height - 1);
[gradient drawInRect:gradientRect angle:270];
}


On 22-Jan-09, at 7:57 AM, Sam Krishna wrote:

I think my understanding of NSGradient's use may be off here....

I'm trying to create a custom NSView that uses NSGradient to shade the view in such a way that it mimics Apple's two-tints NSView. You can see the color scheme at the bottom left hand corner of Mail and the NSView at the bottom of Automator (I'm sure there are other apps, but I can't figure out which ones they are).

Here's the code I'm using for -drawRect:

- (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];
}


Am I using the right NSGradient method? Is it the right angle?

I tried using -drawFromPoint:toPoint:options:, but that didn't work, either. Any ideas?

Live Playfully,

Sam
-----
If he listens in faith,
finding no fault, a man is free
and will attain the cherished words
of those who act in virtue.

_______________________________________________

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

_______________________________________________

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


References: 
 >Reverse-engineering Apple's two-tinted gradient NSViews (From: Sam Krishna <email@hidden>)

  • Prev by Date: Re: Log4Cocoa
  • Next by Date: Re: NSScroller buttons not scrolling?
  • Previous by thread: Re: Reverse-engineering Apple's two-tinted gradient NSViews
  • Next by thread: Re: Reverse-engineering Apple's two-tinted gradient NSViews
  • Index(es):
    • Date
    • Thread