[英]how to call drawrect in UIView variable in a subclass of UIView?
我創建了UIView的子類,在這個類中我聲明了一個UIView變量。 我想調用我的UIView變量的DrawRect,因為現在當我調用DrawRect時,它依賴於我的UIView類,而不是UIView變量,我該怎么做?
對不起,我的英語不好。
你沒有調用drawRect
,你在子視圖上調用setNeedsDisplay
。
你有一個UIViewCustomClass,其中還有一個UIView? 像這樣的東西:
@interface MyView : UIView
{
AnotherView *aView;
}
那就對了 ?
因此,如果要重繪“aView”變量,則必須覆蓋MyView類中的setNeedsDisplay方法:
。H
@interface MyView : UIView
{
AnotherView *aView;
}
- (void)setNeedsDisplay;
-(void) drawRect:(CGRect) r;
@end
.M
@implementation MyView
- (void)setNeedsDisplay
{
[super setNeedsDisplay];
[aView setNeedsDisplay];
}
-(void) drawRect:(CGRect) rect
{
//Do your own custom drawing for the current view
}
@end
編輯:這里,aView也是一個自定義類(AnotherView的類型),所以你可以像我們預先使用MyViewClass一樣覆蓋draw rect方法:
在AnotherView.m中:
@implemetation AnotherView
-(void) drawRect:(CGRect) rect
{
//Do drawing for your aView variable ;)
}
@end
根據蘋果指南,你永遠不應該直接調用drawRect(參見文檔 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.