Objective C:如何更改导航栏中的文本颜色

发布于 2024-11-25 22:30:45 字数 456 浏览 1 评论 0原文

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

navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];

该代码有效,但文本颜色也需要更改(请参见下面的屏幕截图)。此外,右侧的刷新按钮徽标也会受到影响

在此处输入图像描述

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

在此处输入图像描述

问题:如何更改

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

在我更改导航栏的背景颜色之后?

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

enter image description here

The same issue occurs if I navigate to another page in the stack

enter image description here

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜警司 2024-12-02 22:30:45

在 iOS 7 中,只需使用:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

将 [UIColor WhiteColor] 更改为您想要的任何文本颜色

In iOS 7, just use:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

Change [UIColor whiteColor] with whatever text color you want

夏花。依旧 2024-12-02 22:30:45

对于标题,方法如下:

iPhone 导航栏标题文本颜色

自定义按钮的方法如下:

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

For the title here's the way:

iPhone Navigation Bar Title text color

And for the custom buttons here's the way:

adding buttons to ui navigation controller bottom bar

幽梦紫曦~ 2024-12-02 22:30:45

要更改文本颜色:

_navController.navigationBar.titleTextAttributes 
         = @{UITextAttributeTextColor : [UIColor blackColor]};

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

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

[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;

影响导航栏背景的变量:

_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;

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;
⊕婉儿 2024-12-02 22:30:45

我只是组合了一个简单的 UIViewController 子类,它添加了一个可自定义的后退按钮,允许您更改文本颜色。它基本上添加了一些 willAppear/willDisappear 逻辑来为后退按钮设置动画,就像 UINavigationController 在使用 leftBarButtonItem 时所做的那样财产。您可以将其扩展为也执行 rightBarButtomItem。

https://github.com/typeoneerror/BBCustomBackButtonViewController

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.

https://github.com/typeoneerror/BBCustomBackButtonViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文