xcode UINavigationController 风格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5376326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UINavigationController Style
提问by Tunyk Pavel
I created in code UINavigationController, but I want to change style to black translucent
我在代码 UINavigationController 中创建,但我想将样式更改为黑色半透明
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!
但他不会改变。请帮帮我!
回答by BoltClock
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.
是的,你忘了fvc
在你自己的代码中发布。