我有子類UIImageView,並試圖覆蓋drawRect,所以我可以使用Quartz 2D繪製圖像的頂部。我知道這是一個愚蠢的新手問題,但我沒有看到我做錯了什麼。這裏的接口:drawRect沒有在我的UIImageView的子類中調用
#import <UIKit/UIKit.h>
@interface UIImageViewCustom : UIImageView {
}
- (void)drawRect:(CGRect)rect;
@end
和實現:
#import "UIImageViewCustom.h"
@implementation UIImageViewCustom
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
// do stuff
}
- (void)dealloc {
[super dealloc];
}
@end
我設置drawRect
斷點,它從來沒有擊中,導致我覺得它永遠不會被調用。當視圖第一次加載時不應該調用它嗎?我錯誤地覆蓋了它嗎?
請參閱最新的答案,抱歉再次打擾你。 – 2010-04-10 05:09:56
okies。通過文檔我觀察它會工作,如果你製作的UIView而不是UIIMageView的子類,現在你可以在你的子類中添加UIImageView的屬性,我做了一次繪製我的tableview單元格的背景,爲更多的細節,你可以檢查athttp://stackoverflow.com/questions/1784827/draw-a-custom-cell-for-tableview-uitableview-with-changed-colors-and-separa – 2010-04-10 05:33:50