上一篇讲了一点core Graplics的基础东西,这一篇继续讲它的一些属性。
1 线条属性
线宽:CGContextSetLineWidth
连接样式:CGContextSetLineJoin
顶点样式:CGContextSetLineCap
2 绘制虚线
CGContextSetLineDash(ctx, 0, lengths, sizeof(lengths) / sizeof(lengths[0]));
3 设置颜色
填充颜色 [[UIColor redColor] setFill];
描边颜色 [[UIColor yellowColor] setStroke];
填充和描边颜色 [[UIColor blueColor] set];
4 渲染函数
仅描边 CGContextStrokePath(ctx);
仅填充 CGContextFillPath(ctx);
描边并填充 CGContextDrawPath(ctx, kCGPathFill);
填充模式 —— 奇偶填充
1)设置线条属性
- (void)drawRect:(CGRect)rect {
// 1. 获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ctx, 50, 50);
CGContextAddLineToPoint(ctx, 200, 50);
CGContextAddLineToPoint(ctx, 200, 200);
CGContextClosePath(ctx);
// 1> 设置线宽
CGContextSetLineWidth(ctx, 10);
// 2> 设置连接样式
//CGContextSetLineJoin(ctx, kCGLineJoinBevel);
// 3> 设置顶点样式
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextStroke