简体   繁体   中英

How to subclass UINavigationBar to work with Three20/iOS5?

Many of you have probably noticed that we cant anymore create a category to override UINavigationBar drawRect in iOS5. Now actually I don't see a good way of implementing this customization without using a subclass of UINavigationBar and set it inside a navigationController->navigationBar in my MainWindow.xib. However, TTNavigator do not recognize that navigationController since every TTViewController has their own superclass of TTNavigationController .

I don't know how to solve it for Three20 but in general for supporting IOS 5 you can use this method

UIImage *image = [UIImage imageNamed:@"header.png"];

if([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
    //iOS 5 new UINavigationBar custom background
    [navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
} 
else{
    UIImageView *imgView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [imgView setUserInteractionEnabled:NO];
    [imgView setTag:TOOLBAR_TAG];
    [navigationBar insertSubview:imgView atIndex:0];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM