比較難的是CGContextAddArcToPoint
代碼如下:
- CGContextRef context=UIGraphicsGetCurrentContext();
- CGContextSetRGBStrokeColor(context,1,0,0,1);
- CGContextMoveToPoint(context,150,50);
- CGContextAddLineToPoint(context,100,80);
- CGContextAddLineToPoint(context,130,150);
- CGContextMoveToPoint(context,150,50);//圓弧的起始點
- CGContextAddArcToPoint(context,100,80,130,150,50);
- CGContextStrokePath(context);
CGContextMoveToPoint(context,150,50);//圓弧的起始點
CGContextAddArcToPoint(context,100,80,130,150,50);
是說從(150,50)到(100,80)畫一條線,然后再從(100,80)到(130,150)畫一條線,從這兩條線(無限延伸的) 和半徑50可以確定一條弧,
而
CGContextAddArc(context, 100, 100, 30, 0, M_PI, 1);
比較簡單了,(100,100)為圓心的坐標,30為半徑,(0,M_PI)為起始角度和結束角度,1為順時針,0 為逆時針
是說從(150,50)到(100,80)畫一條線,然后再從(100,80)到(130,150)畫一條線,從這兩條線(無限延伸的) 和半徑50可以確定一條弧