【发布时间】:2011-07-20 14:33:31
【问题描述】:
我将 XCode 4.0.2 用于 iOS4 项目。
我有一个MainView.xib 和一个MainViewController。
我在MainView.xib 中插入了一个UIImageView 和一张图片。
在 Identity Inspector 中,我给 UIImageView 一个自定义类图。
我创建了两个新文件Diagram.h 和Diagram.c。在Diagram.m我已经插入了
- (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);
}
当我运行应用程序时,我可以看到图像(在UIImageView,但绘图没有完成。也许没有调用。我该怎么办?
谢谢。
【问题讨论】:
-
如果你删除图像,你能看到在你的
drawRect方法中发生的绘图吗?即UIImageView是否在您的自定义绘图之上绘制图像。 -
不,图片下方没有绘图。
标签: iphone ios4 uiimage drawing