2011-07-20 39 views
0

我正在为iOS4项目使用XCode 4.0.2。如何绘制UIImageView(iOS4)

我有一个MainView.xibMainViewController

我在MainView.xib中插入了UIImageView的图像。

在Identity Inspector中,我给UIImageView一个自定义的类图。

我创建了两个新文件Diagram.hDiagram.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,但图纸不这样做,也许不叫,我该怎么办?

谢谢。

+0

更详细如果删除图像,你可以看到发生在你的'drawRect'方法图纸吗?即“UIImageView”是在您的自定义绘图上绘制图像。 –

+0

不,图像下没有绘图。 – boscarol

回答

1

答案就在苹果官方文档

特别注意事项

UIImageView类经过优化将其图像绘制到显示屏上。 UIImageView不会在子类上调用drawRect:。如果您的子类需要自定义绘图代码,建议您使用UIView作为基类。

你可以看到this question

相关问题