• 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: Drawing issues in custom view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing issues in custom view


  • Subject: Re: Drawing issues in custom view
  • From: Jason Wiggins <email@hidden>
  • Date: Fri, 11 Jul 2008 02:30:42 +1000

Not to worry, just realised what is happening. drawRect: gets called for ALL drawing operations in the view, not just background as I expected.
Carry on...


Regards,
Jason



On 11/07/2008, at 1:38 AM, Jason Wiggins wrote:

Hi everyone,

I have a Custom View in IB with an rounded NSTokenField (Focus ring set to none) and a rounded rect NSButton embedded in it. In XCode I have the Custom View class set to my subclass of NSView, with the following code:

- (void)drawRect:(NSRect)rect {
	NSGradient *gradient = nil;
	NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
	[[NSColor blackColor] setFill];
	[path fill];

// Create gloss gradient
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.3]
endingColor:[NSColorcolorWithCalibratedWhite:1.0alpha: 0.2]];
// Make a half-height rectangle
rect = NSMakeRect(rect.origin.x, (rect.origin.y + (rect.size.height)/2), rect.size.width, (rect.size.height)/2);

path = [NSBezierPath bezierPathWithRect:rect];
[gradient drawInBezierPath:path angle:-90];


// Create upper highlight
path = [NSBezierPath bezierPath];
[path moveToPoint:NSMakePoint(rect.origin.x, (rect.origin.y + rect.size.height))];
[path lineToPoint:NSMakePoint(rect.size.width, (rect.origin.y + rect.size.height))];
[path closePath];
[path setLineWidth:2];
[[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setStroke];
[path stroke];
}


The gradient draws as expected. The upper highlight also draws as expected in the view, but also on the NSTokenView and NSButton, which is unexpected and I don't know why this is so. Can anyone offer any info as to why this is the case?

Regards,
JJ
_______________________________________________

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


  • Follow-Ups:
    • Re: Drawing issues in custom view
      • From: "Michael Ash" <email@hidden>
    • Re: Drawing issues in custom view
      • From: "I. Savant" <email@hidden>
References: 
 >Drawing issues in custom view (From: Jason Wiggins <email@hidden>)

  • Prev by Date: Re: Why can't I name a property `tag'?
  • Next by Date: Re: Printing a Webview
  • Previous by thread: Drawing issues in custom view
  • Next by thread: Re: Drawing issues in custom view
  • Index(es):
    • Date
    • Thread