3
我想要子類UINavigationBar
,以便我可以在其drawRect:
中進行自定義繪圖。自定義drawRect:在UINavigationBar子類
這裏是我的代碼:
導航控制器(.H)
@interface CORENavigationController : UINavigationController
@property (strong, nonatomic) CORENavigationBar *customNavigationBar;
@end
導航控制器(.M)
@implementation CORENavigationController
@synthesize customNavigationBar = _customNavigationBar;
- (UINavigationBar *)navigationBar {
if (![self customNavigationBar]) {
[self setCustomNavigationBar:[[CORENavigationBar alloc] init]];
}
return [self customNavigationBar];
}
導航欄(.H)
@interface CORENavigationBar : UINavigationBar
@end
導航欄(.M)
@implementation CORENavigationBar
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
}
的問題是,在導航欄沒有標題,例如我能看到的只是標準的藍色背景。
只要我刪除了下面的方法,標題是後面有:
- (UINavigationBar *)navigationBar {
if (![self customNavigationBar]) {
[self setCustomNavigationBar:[[CORENavigationBar alloc] init]];
}
return [self customNavigationBar];
}
爲什麼標題消失?我打電話給super
的drawRect:
,不要改變別的。
謝謝!
問題不清楚。 「只要我刪除這個方法」是哪種方法? drawRect還是冒號後面的那個?如果它是'drawRect',那麼這是一個非常有趣的問題;) –
@Yar固定。這是冒號後面的方法。簡單地說,只要我不重寫'navigationBar',標題就回到那裏。希望它更清晰。感謝評論! –
'navigationBar'方法有可能返回'UINavigationBar'的具體子類,或者至少設置實例。調試並看看。 –