2011-07-20 38 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

相關問題