开发者

Changing the navigationBar on pushViewController:

In my tabBar based app I have subclassed the UINavigationBar. Let'开发者_运维百科s say I have three of them: BlueNavBar, BlackNavBar and RedNavBar. It looks something like this:

        //BlueNavBar.m
        - (void)drawRect:(CGRect)rect {
            self.tintColor = [UIColor colorWithRed:65.0f/255.0f green:(156.0f/255.0f) blue:(215.0f/255.0f) alpha:1.0];
            UIImage *image = [[UIImage imageNamed:@"blueNavBar.png"]retain];    
            [image drawInRect:rect];
            [image release];    
        }

I've assigned the subclassed navigationbar for each tab with Interface Builder. That is working great, no problems there.

In some viewControllers however i want to change the navigationBar during "pushViewController". Let's say I want to change the current navigationbar (which is for e.g. BlueNavBar) to the RedNavBar. How can I do this programmatically, without Interface Builder?


It depends on how you've designed the view controller classes themselves. One way to design what you need would be to set the navigation bar type (i.e. colour) when you create the view controller, before you push it on the stack. Something like:

SomeViewController* someViewController = [[SomeViewController alloc] initWithNibName:@"SomeView" bundle:nil];
someViewController.navigationBarStyle = NBStyleRed; // NBStyleRed defined as an enum somewhere
[self.navigationController pushViewController:someViewController animated:YES];
[someViewController release];

The setter method for navigationBarStyle would then (re)create an appropriately-coloured navigation bar for the view controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜