JWo*_*ood 1 iphone cocoa-touch core-graphics
我正在使用Core Graphics绘制一条宽度为4像素的任意线,现在我希望这条线具有另一种颜色的1像素轮廓.我看不到任何能够实现这种"开箱即用"的CG功能,但我正在寻找有关如何实现这一目标的建议.这是我现有的代码:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);
CGPoint curPoint = [(NSValue*)[points objectAtIndex:0] CGPointValue];
CGContextMoveToPoint(context, curPoint.x, curPoint.y);
for( int i = 1; i < [points count]; i++ ) {
curPoint = [(NSValue*)[points objectAtIndex:i] CGPointValue];
CGContextAddLineToPoint(context, curPoint.x, curPoint.y);
CGContextStrokePath(context);
CGContextMoveToPoint(context, curPoint.x, curPoint.y);
}
Run Code Online (Sandbox Code Playgroud)
这会产生单线.我想生产一条4px线,1px线突出显示4px线,如下所示:
iOS 5.0添加了一项新功能CGPathCreateCopyByStrokingPath(),可以满足您的需求.
首先CGPathRef为黑色路径创建一个,然后用它创建一个副本CGPathCreateCopyByStrokingPath().
这将为您提供一条新路径,您可以用黑色和笔划填充红色,以获得您想要的.
此外,创建路径有点慢.执行屏幕绘制时应避免创建路径.在开始绘制到屏幕之前,所有路径都应存储在RAM中并准备就绪.drawRect:应该只绘制路径,而不是创建它.
| 归档时间: |
|
| 查看次数: |
1979 次 |
| 最近记录: |