开发者

Best point to overwrite the navigationBar property of navigationController

开发者 https://www.devze.com 2023-01-01 08:24 出处:网络
I\'m overwriting UINavigationController to replace the default navigationBar property with an instance of my own subclass of UINavigationBar. So I tried something like

I'm overwriting UINavigationController to replace the default navigationBar property with an instance of my own subclass of UINavigationBar. So I tried something like

_navigationBar = [[SBNavigationBar alloc] init];

in my -initWithRootViewController:. But that开发者_开发知识库 didn't work out as I expected it. There's still the default navigationBar being displayed.

So what's the best point to overwrite the navigationBar?

Thanks in advance

–f


If you check the documentation http://developer.apple.com/iphone/library/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html, you'll see that the navigationBar property is read-only.

To have a custom navigationBar you can use Categories for example. You will find many questions answering this here on stackoverflow.

One simple version is putting an image in drawRect: like so...

@implementation UINavigationBar (Custom)

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"bg_toolbar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

@end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号