在ios中以顺时针方向绘制圆弧

时间:2014-02-12 09:54:54

标签: ios objective-c ipad cgcontext

如何从零开始顺时针方向绘制弧形环。我需要弧从0开始,弧终点可以变化。如图像Circular progress

所示

1 个答案:

答案 0 :(得分:0)

我想要的是从左侧开始一个弧线。( - 180)我这样做了

circular

-(void)drawRect:(CGRect)rect{

[super drawRect:rect];

CGRect customRect = rect;
customRect.origin.x = 5;
customRect.origin.y = 6;
customRect.size.width = rect.size.width -10;
customRect.size.height = rect.size.height - 12;


radius = customRect.size.width/2 - ((customRect.size.width/2)*0.3);


CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextFillEllipseInRect (ctx, customRect);
CGContextStrokeEllipseInRect(ctx, customRect);
CGContextFillPath(ctx);
CGContextSetRGBStrokeColor(ctx, 0.0, 0.0, 1.0, 1.0);
CGContextAddArc(ctx, self.frame.size.width/2  , self.frame.size.height/2, radius , -M_PI, ToRad(self.angle), 0);

CGContextSetLineWidth(ctx, customRect.size.width/2 - (radius + 2));
CGContextDrawPath(ctx, kCGPathStroke);
}