Core Graphics核心绘图 ( 二)

上一篇讲了一点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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值