目标C:如何在导航栏中更改文本颜色

Zhe*_*hen 14 icons objective-c textcolor uinavigationbar ios

我通过以下代码更改了导航栏颜色

navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];
Run Code Online (Sandbox Code Playgroud)

代码工作但文本颜色也需要更改(见下面的截图).此外,右侧的刷新按钮徽标也会受到影响

在此输入图像描述

如果我导航到堆栈中的另一个页面,则会出现同样的问题

在此输入图像描述

问题:如何更改颜色

  • 标题文字
  • 后退按钮文本和
  • 右栏按钮图标颜色?

我改变了导航栏的背景颜色后?

Erw*_*wan 16

在iOS 7中,只需使用:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
Run Code Online (Sandbox Code Playgroud)

使用您想要的任何文本颜色更改[UIColor whiteColor]


Err*_*Efe 15

这里的标题是这样的:

iPhone导航栏标题文字颜色

对于自定义按钮,这里的方式是:

添加按钮到ui导航控制器底栏


has*_*san 6

要更改文字颜色:

_navController.navigationBar.titleTextAttributes 
         = @{UITextAttributeTextColor : [UIColor blackColor]};
Run Code Online (Sandbox Code Playgroud)

添加刷新按钮并为其着色:

UIBarButtonItem *button = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
         target:self action:@selector(reload)];

[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;
Run Code Online (Sandbox Code Playgroud)

影响导航栏背景的变量:

_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)