• 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: Rounded NSBox/NSView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounded NSBox/NSView?


  • Subject: Re: Rounded NSBox/NSView?
  • From: Graham Cox <email@hidden>
  • Date: Tue, 6 Oct 2009 14:07:13 +1100


On 04/10/2009, at 4:35 AM, PCWiz wrote:

I want to create a NSBox or an NSView (doesn't matter which one) that has rounded corners. Now I know about NSBox's setCornerRadius method, and using NSBezierPath in an NSView subclass to draw a rounded rect. The problem with these 2 methods is that even though the rounded corners are drawn, anything inside the view (e.g. a table view) does not have rounded corners, only the view itself does. Is there any workaround for this?


Views are defined by their frame/bounds rectangles. But there's nothing to stop you from setting a round-cornered clipping path at the start of your view's drawRect method to clip the view's content to a round-cornered rect. Since the view draws nothing by default, the fact that the "real" edge is a rectangle will not be apparent.


- (void) drawRect:(NSRect) updateRect
{
[NSGraphicsContext saveGraphicsContext];
NSBezierPath* roundRectPath = [NSBezierPath bezierPathWithRoundedRect: [self bounds] xRadius:16 yRadius:16];
[roundRectPath addClip];


	// draw the rest of the view's content


[NSGraphicsContext restoreGraphicsState]; }


(warning: typed into Mail)

--Graham


_______________________________________________

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: Rounded NSBox/NSView?
      • From: Rob Keniger <email@hidden>
References: 
 >Rounded NSBox/NSView? (From: PCWiz <email@hidden>)

  • Prev by Date: Re: wait for the event?
  • Next by Date: Re: Checking whether a file is a genuine PDF file
  • Previous by thread: Re: Rounded NSBox/NSView?
  • Next by thread: Re: Rounded NSBox/NSView?
  • Index(es):
    • Date
    • Thread