ios 目标 C:如何更改导航栏中的文本颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6805025/
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
Objective C: How to change text color in navigation bar
提问by Zhen
I have changed my navigation bar color via the following code
我通过以下代码更改了我的导航栏颜色
navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];
The code worked but the text color also needs to be changed (see screenshot below). Also the refresh button logo on the right is affected as well
代码有效,但文本颜色也需要更改(见下面的截图)。右侧的刷新按钮标志也受到影响
The same issue occurs if I navigate to another page in the stack
如果我导航到堆栈中的另一个页面,则会出现同样的问题
Question: How can I change the color of the
问题:我怎样才能改变颜色
- title text
- Back button text and
- right bar button icon color?
- 标题文字
- 后退按钮文本和
- 右栏按钮图标颜色?
After I changed the background color of the navbar?
更改导航栏的背景颜色后?
回答by Erwan
In iOS 7, just use:
在 iOS 7 中,只需使用:
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
Change [UIColor whiteColor] with whatever text color you want
使用您想要的任何文本颜色更改 [UIColor whiteColor]
回答by Erre Efe
For the title here's the way:
对于标题,方法如下:
iPhone Navigation Bar Title text color
And for the custom buttons here's the way:
对于自定义按钮,方法如下:
回答by hasan
To change text color:
要更改文本颜色:
_navController.navigationBar.titleTextAttributes
= @{UITextAttributeTextColor : [UIColor blackColor]};
Adding refresh button and color it:
添加刷新按钮并为其着色:
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(reload)];
[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;
Variables that effect navigation bar background:
影响导航栏背景的变量:
_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;
回答by typeoneerror
I just put together a simple UIViewController
subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear
/willDisappear
logic to animate the back button the way the UINavigationController
does while using the leftBarButtonItem
property. You might extend this to also do the rightBarButtomItem as well.
我只是组合了一个简单的UIViewController
子类,它添加了一个可自定义的后退按钮,允许您更改文本颜色。它基本上添加了一些willAppear
/willDisappear
逻辑,以UINavigationController
在使用leftBarButtonItem
属性时为后退按钮设置动画。您可以将其扩展为也执行 rightBarButtomItem。
https://github.com/typeoneerror/BBCustomBackButtonViewController
https://github.com/typeoneerror/BBCustomBackButtonViewController