I want to subclass UINavigationBar
so that I can do custom drawing in its drawRect:
.
Here's my code:
Navigation Controller (.h)
@interface CORENavigationController : UINavigationController
@property (strong, nonatomic) CORENavigationBar *customNavigationBar;
@end
Navigation Controller (.m)
@implementation CORENavigationController
@synthesize customNavigationBar = _customNavigationBar;
- (UINavigationBar *)navigationBar {
if (![self customNavigationBar]) {
[self setCustomNavigationBar:[[CORENavigationBar alloc] init]];
}
return [self customNavigationBar];
}
Navigation Bar (.h)
@interface CORENavigationBar : UINavigationBar
@end
Navigation Bar (.m)
@implementation CORENavigationBar
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
}
The issue is that the navigation bar has no title, e.g. all I can see is just the standard blue background.
As soon as I remove the following method, the title is back there:
- (UINavigationBar *)navigationBar {
if (![self customNavigationBar]) {
[self setCustomNavigationBar:[[CORENavigationBar alloc] init]];
}
return [self customNavigationBar];
}
Why does the title disappear? I call the super
's drawRect:
and do not change anything else.
Thanks!