Re: Round Corners With BezierPath
Re: Round Corners With BezierPath
- Subject: Re: Round Corners With BezierPath
- From: Dan Messing <email@hidden>
- Date: Wed, 23 Aug 2006 14:10:10 -0500
That one seems overly complicated. You don't actually have to draw
the lines yourself, just adding the arcs will do it. Here's a simpler
NSBezierPath category method that also takes care of making sure the
radius is small enough for you ( think I originally got this from
cocoadev.com or something). Basically the same thing, just a little
more concise.
+ (NSBezierPath*)bezierPathWithRoundRectInRect:(NSRect)aRect radius:
(float)radius
{
NSBezierPath* path = [self bezierPath];
radius = MIN(radius, 0.5f * MIN(NSWidth(aRect), NSHeight(aRect)));
NSRect rect = NSInsetRect(aRect, radius, radius);
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMinY(rect)) radius:radius startAngle:180.0 endAngle:270.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMinY(rect)) radius:radius startAngle:270.0 endAngle:360.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMaxY(rect)) radius:radius startAngle:0.0 endAngle:90.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMaxY(rect)) radius:radius startAngle:90.0 endAngle:180.0];
[path closePath];
return path;
}
Dan Messing
Stunt Software
http://www.stuntsoftware.com/
Hi,
I am trying to draw a rectangle with round corners using NSBezierPath
and I am not having much luck.
Got archives?
<http://www.cocoabuilder.com/archive/message/cocoa/2001/8/28/39916>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden