我尝试绘制一条线,其中每一端都有一个圆形点,并将其作为图层添加到视图中。我有一般的概念,但正如你从屏幕截图中看到的那样,这条线有点错位,我还没有找到原因。
我也不确定为什么会有一条线开始(正如你所看到的,我已经注释掉了应该用来画线的两条线,但是无论如何都画了一条线。)
//Draw circle
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];
//Add second circle
[path addArcWithCenter:CGPointMake(200.0, 200.0) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];
//[path addLineToPoint:CGPointMake(200.0, 200.0)];
//[path moveToPoint:CGPointMake(200.0, 200.0)];
[path closePath];
[[UIColor redColor] setStroke];
[[UIColor redColor] setFill];
[path stroke];
[path fill];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor redColor] CGColor];
shapeLayer.lineWidth = 4.0;
shapeLayer.fillColor = [[UIColor redColor] CGColor];
[self.view.layer addSublayer:shapeLayer];
感谢任何帮助!
答案 0 :(得分:1)
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];
//Add second circle
[path moveToPoint:CGPointMake(100.0, 100.0)];
[path addLineToPoint:CGPointMake(200, 200)];
[path moveToPoint:CGPointMake(200, 200)];
[path addArcWithCenter:CGPointMake(200, 200) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];