Ale*_*one 20 colors objective-c storyboard uinavigationcontroller ios
此代码可以更改UINavigationBar应用程序中任何位置的颜色.但是,我注意到它并没有改变UIColor所UINavigationBar使用的 UINavigationController(我来自a UIStoryboard).
UIColor* navBarColor = [UIColor colorWithRed:arc4random()%100/100.0
green:arc4random()%100/100.0
blue:arc4random()%100/100.0
alpha:1];
[[UINavigationBar appearance] setTintColor:navBarColor];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setAlpha:0.7];
Run Code Online (Sandbox Code Playgroud)
有没有办法访问导航栏的appearance对象UINavigationController's?我知道如何设置单个控制器的色调,但我想对它们的外观进行全局控制.
更新:这是我的错误,代码确实改变了UIColor所有UINavigationBars,但它需要覆盖和揭示根导航控制器(例如呈现模态视图控制器),然后它将重新绘制自己的新UIColors!
谢谢!
Ash*_*ish 19
现在在iOS 8中,我们可以通过以下方式设置色彩: -
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
dem*_*733 14
当你宣布你的时候UINavigationController,试试这个:
UINavigationController *myNavController =
[[UINavigationController alloc] initWithRootViewController:myRootViewController];
myNavController.navigationBar.tintColor =
[UIColor colorWithRed:arc4random() % 100 / 100.0f
green:arc4random() % 100 / 100.0f
blue:arc4random() % 100 / 100.0f
alpha:1.0f];
Run Code Online (Sandbox Code Playgroud)
Nil*_*esh 13
您可以使用appearance代理全局更改条形颜色:
NSDictionary *textTitleOptions =
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
textTitleOptions =
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor],
UITextAttributeTextColor, nil];
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
[[UIToolbar appearance] setTintColor:[UIColor redColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)