I have a view that I want to add some custom drawing to.
I know how to do this with a View that isn't connected to a Nib/Xib file - you write the drawing code in the -drawRect:
method.
But if I init the view using
[[MyView alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
-drawRect:
of course doesn't get called. I tried doing the below code in -viewDidLoad
CGRect rect = [[self view] bounds];
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ref, 2.0);
CGContextSetRGBStrokeColor(ref, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(ref, 0, 0, 0, 0);
CGContextAddRect(ref, CGRectMake(1, 1, rect.size.width - 10, rect.size.height - 10));
CGContextStrokePath(ref);
CGContextDrawPath(ref, kCGPathFillStroke);
but nothing get drawn. Any ideas?