This is my first time drawing, so it must be something very stupid, but my drawRect: method doesn’t work…
Here is my code:
- (void)drawRect:(CGRect)rect {
CGPoint center = CGPointMake(self.bounds.origin.x + self.bounds.size.width / 2, self.bounds.origin.y + self.bounds.size.height / 2);self.bounds.origin.y + self.bounds.size.height / 2)
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor redColor] setStroke];
CGFloat radius = (self.bounds.size.width > self.bounds.size.height) ? self.bounds.size.width - 30 : self.bounds.size.height - 30;
CGContextBeginPath(ctx);
CGContextAddArc(ctx, center.x, center.y, radius, 0, 2 * M_PI, YES);
CGContextStrokePath(ctx);
}
The radius of an arc is measured from its center. You’re using almost the entire view’s width/height, so that the arc will be drawn outside of the visible area. Use a smaller radius and you’ll see your arc.
Btw, if all you want is to draw a circle (an arc with an angle of 2π is the same),
CGContextAddEllipseInRectis easier to use.