I am using XCode 4.0.2 for a iOS4 project.
I have a MainView.xib
and a MainViewController
.
I have inserted an UIImageView
in the MainView.xib
with an image.
In the Identity Inspector, I give the UIImageView
a custom class Diagram.
I created two new file Diagram.h
and Diagram.c
. In Diagram.m
I have inserted
- (void)drawRect:(CGRect)rect {
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {0.0, 0.0, 1.0, 1.0};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 200, 200);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
}
When I run the app, I can see the image (in UIImageView
, but the drawing is not done. Perhaps is not called. How can I do?
Thank you.