[英]How to make a draw over an UIImageView (iOS4)
我將 XCode 4.0.2 用於 iOS4 項目。
我有一個MainView.xib
和一個MainViewController
。
我在MainView.xib
中插入了一個帶有圖像的UIImageView
。
在 Identity Inspector 中,我給UIImageView
一個自定義 class 圖。
我創建了兩個新文件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
中,但繪圖沒有完成。也許沒有調用。我該怎么辦?
謝謝你。
答案在 Apple 官方文檔中
特別注意事項
UIImageView class 經過優化,可將其圖像繪制到顯示器上。 UIImageView 不會在子類上調用 drawRect:。 如果您的子類需要自定義繪圖代碼,建議您使用 UIView 作為基礎 class。
您可以查看有關此問題的更多詳細信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.