OK, so I have what should be a simple question, so here goes. I've created a class that subclasses UIView, and all it should do is draw a circle on the view I put it in. The class is called Ball and here is the relevant code for it:
- (id)initWithFrame

CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
self.backgroundColor = [self.superview backgroundColor];
return self;
}
else
return nil;
}
- (void)drawRect

CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextSetFillColorWithColor(context, currentColor.CGColor);
CGContextAddEllipseInRect(context, self.frame);
CGContextDrawPath(context, kCGPathFillStroke);
}
I created a UIViewController, and tried to add an instance of Ball to it, but where I specified Ball's frame I just get a solid black square. This is the code in the UIViewController where I try to instantiate and display the 'Ball'.
- (void)viewDidLoad {
[super viewDidLoad];
ball = [[Ball alloc] initWithFrame:CGRectMake(100, 100, 40, 40)];
ball.currentColor = [UIColor redColor];
[self.view addSubview:ball];
[self.view setNeedsDisplay];
}
I've set a breakpoint, and I know that the drawRect method of Ball is getting called, but I get a black square instead of a red circle.
Does anyone see where I might have gone wrong here?
Thanks in advance.