I want a subclass UINavigationBarso that I can make a custom drawing in drawRect:.
Here is 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 problem is that there is no title in the navigation bar, for example. all i see is just a standard blue background.
As soon as I delete the following method, the header returns there:
- (UINavigationBar *)navigationBar {
if (![self customNavigationBar]) {
[self setCustomNavigationBar:[[CORENavigationBar alloc] init]];
}
return [self customNavigationBar];
}
Why does the name disappear? I call super drawRect:and do not change anything.
Thank!
source
share