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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to