How to draw a rounded rectangle in Core Graphics / Quartz 2D?

dontWatchMyProfile picture dontWatchMyProfile · May 14, 2010 · Viewed 79.5k times · Source

I need to draw an outline for a rounded rectangle. I know I can make lines and arcs, but maybe there is also a function for rounded rects?

Answer

Timo Bruck picture Timo Bruck · Jan 25, 2012

Instead of making your own path out of lines and arcs, you can use

[UIBezierPath bezierPathWithRoundedRect:cornerRadius:]

or

[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]

(the second one lets you specify which corners are rounded)

Available in iOS 3.2 or later.