• 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: Round Corners With BezierPath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: NSTableColumn sort indicator
  • Next by Date: Bindings Problem: KVO Not Being triggered?
  • Previous by thread: Re: Round Corners With BezierPath
  • Next by thread: Re: Round Corners With BezierPath
  • Index(es):
    • Date
    • Thread