0
- (void)drawRect:(CGRect)rect {
[[UIColor redColor] set];

UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 2.f;
[path addArcWithCenter:CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2) radius:self.frame.size.width / 2 startAngle:M_PI_2 endAngle:M_PI * 3 / 2.f clockwise:YES];
[path addLineToPoint:CGPointMake(self.frame.size.width, 0)];
[path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
[path closePath];

CGFloat dashPattern[] = {4.f,1.f}; //make your pattern here

[path setLineDash:dashPattern count:2 phase:0.f];

[path stroke];

} enter image description here

As you see from the above, the path line width is set to 2.f, but the arc's line width is thicker than the lines. What goes wrong with this code, and how to make the arc and the line the same width? Any answers are greatly appreciated. ^_^

Edited:

Thanks to the help of rob mayoff, the problem has been solved.

- (void)drawRect:(CGRect)rect {
    CGFloat dash[] = {4, 1};
    [[UIColor orangeColor] set];
    UIBezierPath *roundPath = [UIBezierPath bezierPath];

    [roundPath addArcWithCenter:CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2) radius:(self.frame.size.width / 2 - 0.5) startAngle:M_PI_2 endAngle:M_PI * 3 / 2.f clockwise:YES];
    [roundPath setLineDash:dash count:2 phase:0];
    [roundPath stroke];

    UIBezierPath *linePath = [UIBezierPath bezierPath];
    linePath.lineWidth = 2.f;
    [linePath moveToPoint:CGPointMake(self.frame.size.width / 2, 0)];
    [linePath addLineToPoint:CGPointMake(self.frame.size.width, 0)];
    [linePath moveToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
    [linePath addLineToPoint:CGPointMake(self.frame.size.width / 2, self.frame.size.height)];
    [linePath setLineDash:dash count:2 phase:0];
    [linePath stroke];
}

enter image description here

tounaobun
  • 14,570
  • 9
  • 53
  • 75

0 Answers0