我按照
对圆角进行四舍五入定义coloredBoxRect并计算min和max x和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);
然后做
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);
签名之一CGPathAddArcToPoint是第一和第二直线切线的x和y坐标。例如,为右上角添加弧)maxx + miny + maxx + maxy。而这些参数现在让我感到困惑。
我试图画一幅画,注意到(maxx,miny)不是切线的坐标。这对只是矩形右上角的坐标.........
是否有人就此问题向我提出建议。欢迎所有评论。 感谢
答案 0 :(得分:1)
按一个数量级更简单的方法是使用[UIBezierPath bezierPathWithRoundedRect:cornerRadius:]
。然后,您可以从中获取CGPath。
见documentation。这可能在幕后做同样的事情,但为什么还要自己去做呢?