Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController Style

I created in code UINavigationController, but I want to change style to black translucent

FirstViewController *fvc = [[FirstViewControlelr alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] init];
navcon.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[navcon pushViewController:fvc animated:NO];
[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];
return YES;

But he doesn't change. Help me please!

like image 592
Tunyk Pavel Avatar asked Mar 21 '11 10:03

Tunyk Pavel


People also ask

What is a Uinavigationcontroller?

A container view controller that defines a stack-based scheme for navigating hierarchical content.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar.

Can you change the navigation bar on iPhone?

Change the Bar Style A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

What is Navigationitem?

The navigation item used to represent the view controller in a parent's navigation bar.


1 Answers

I suspect it has something to do with the fact that you're accessing a navigation controller's navigation controller. Your navigation controller doesn't live in another navigation controller, so you're setting the bar style of something that isn't there.

You want this:

navcon.navigationBar.barStyle = UIBarStyleBlackTranslucent;

Also you can make a navigation controller and immediately initialize it with a root view controller so you don't have to push it in manually, like this:

FirstViewController *fvc = [[FirstViewController alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:fvc];
[fvc release];

navcon.navigationBar.barStyle = UIBarStyleBlackTranslucent;

[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];

return YES;

And yes, you forgot to release fvc in your own code.

like image 185
BoltClock Avatar answered Sep 21 '22 17:09

BoltClock