将边框颜色和圆角添加到CGMutableRefPath

时间:2013-01-10 00:39:51

标签: iphone ios objective-c ipad

我在drawRect上有以下代码:

  CGMutablePathRef pathRef = CGPathCreateMutable();
     CGPathMoveToPoint(pathRef, NULL, 0, 220);
     CGPathAddLineToPoint(pathRef, NULL, rect.size.width, 220);
     CGPathAddLineToPoint(pathRef, NULL, rect.size.width, rect.size.height);
     CGPathAddLineToPoint(pathRef, NULL, 0, rect.size.height);
     CGPathCloseSubpath(pathRef);

如何为此添加黑色边框?

1 个答案:

答案 0 :(得分:1)

确保您有上下文:

CGContextRef context = UIGraphicsGetCurrentContext();

然后:

aColor = [UIColor blackColor];
[aColor setStroke];
CGContextSetLineWidth(context, 2.0f);
CGContextAddPath(context, pathRef);
CGContextStrokePath(context);