I am rounding the corners of a rectangle by following
Define a coloredBoxRect and calculate min, max of x and y
CGFloat coloredBoxMargin = 8;
CGFloat coloredBoxHeight = 40.0;
coloredBoxRect = CGRectMake(coloredBoxMargin, coloredBoxMargin, self.bounds.size.width-coloredBoxMargin*2, coloredBoxHeight);
CGFloat minx = CGRectGetMinX(coloredBoxRect);
CGFloat miny = CGRectGetMinY(coloredBoxRect);
CGFloat midx = CGRectGetMidX(coloredBoxRect);
CGFloat midy = CGRectGetMidY(coloredBoxRect);
CGFloat maxx = CGRectGetMaxX(coloredBoxRect);
CGFloat maxy = CGRectGetMaxY(coloredBoxRect);
Then doing
CGMutablePathRef path = CGPathCreateMutable();
//Path stars here
CGPathMoveToPoint (path, NULL, midx, miny);
// Add an arc for the upper right corner
1.CGPathAddArcToPoint(path, NULL, maxx, miny, maxx, maxy, radius);
//Add an arc for the lower right corner
2.CGPathAddArcToPoint(path, NULL, maxx, maxy, minx, maxy, radius);
// Add an arc for the lower left corner
3.CGPathAddArcToPoint(path, NULL, minx, maxy, minx, miny, radius);
// Add an arc for the upper left corner
4.CGPathAddArcToPoint(path, NULL, minx, miny, maxx, miny, radius);
CGPathCloseSubpath(path);
CGContextAddPath(context, path);
One of signatures CGPathAddArcToPoint are x and y coordinates of the first and second line tangent. For example to add arc for upper right corner ) maxx+miny+maxx+maxy. And these parameters are confusing me now.
I tried to draw a picture and noticed that (maxx,miny) is not the coordinate of the tangent line. This pair is just a coordinate of top right corner of rectangle………
Does someone advice me on this issue. All comments are welcomed here.
Thanks
Simpler by an order of magnitude is to use
[UIBezierPath bezierPathWithRoundedRect:cornerRadius:]. You can then get the CGPath from it afterwards.See documentation. This probably does the same thing behind the scenes, but why bother doing it yourself?