crazy_tiger_corp crazy_tiger_corp - 1 year ago 80
Objective-C Question

UIBezier Path Refusing to Draw

I'm trying to draw a arch using

. There are no errors or warnings and I cannot see any obvious bugs but it just will not draw. This is my code:

- (void)drawRect:(CGRect)rect {

CGFloat a = 10;

CGFloat width = CGRectGetWidth(self.bounds);
CGFloat height = CGRectGetHeight(self.bounds);

CGPoint center = CGPointMake(width/2, height/2);
CGFloat radius = MAX(width, height);
CGFloat archWidth = 18;
CGFloat archLengthPerA = 5;
CGFloat startAngle = 3 * M_PI /2;
CGFloat endAngle = archLengthPerA * a + startAngle;

UIBezierPath* path = [UIBezierPath bezierPath];
[path addArcWithCenter:center

path.lineWidth = archWidth;
[[UIColor colorWithRed:255 green:17 blue:0 alpha:1.0] setStroke];
[path stroke];

I put it in a separate view to test and it crashed on
so is that anything to do with it? I tried adding a breakpoint to see if it worked without it but then it crashed again. Any ideas why it's not working?

Answer Source

Your value of radius is too large, so the arc is drawn outside of the view.

Make it smaller. For instance:

CGFloat radius = MIN(width/2, height/2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download