美文网首页
使用drawRect绘制线条

使用drawRect绘制线条

作者: 水跃龙纹 | 来源:发表于2017-07-06 16:41 被阅读0次

CGContextRef context = UIGraphicsGetCurrentContext();

kCGLineCapButt,        两头平

kCGLineCapRound,    两头圆

kCGLineCapSquare    两头平

CGContextSetLineCap(context, KCGLineCapRound)

CGContextSetLineWith(context, 10);//线宽

CGContextSetAllowsAntialiasing(context, true);//锯齿

CGContextSetRGBStrokeColor(context, 70.0 / 255.0, 241.0 / 255.0, 241.0 / 255.0, 1.0);//颜色

CGContextBeginPath(context);

CGContextMoveToPoint(context, 50,50);  //起点坐标

//1.    CGContextAddLineToPoint(context, 300, 500);  //终点坐标

// 2.   CGContextAddArcToPoint(context,50, 80, 100, 400, 30); //直线到点(50,80)然后到点(100,400)的半径为30的弧线

//3.    CGContextAddArc(context, 100, 100, 50, 15, 60, 0);//绘制圆形 中心坐标,半径,起始弧,结束弧,顺时针,1为逆时针

CGContextStrokePath(context);

注意:drawRect方法是系统的方法,不用你调用,但如果你碰到绘制的图并没有显示出来,你可以在viewcontroller中调用[line setNeedsDisplay];方法,这个方法会将drawRect方法给调出来(但你不能直接操作drawRect)

相关文章

网友评论

      本文标题:使用drawRect绘制线条

      本文链接:https://www.haomeiwen.com/subject/loohhxtx.html