iOS7导航栏文字颜色

问题描述 投票:20回答:6

我在将文本和状态栏文本颜色更改为白色时遇到问题。

我希望所有的黑色文字都是白色的,任何想法?

我见过很多解决方案,但似乎没有一个在iOS 7上运行

iphone ios7
6个回答
55
投票

我的解决方案是将以下内容添加到AppDelegate:

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

斯威夫特3:

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]

斯威夫特5:

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]

29
投票

要将标题文字颜色变为白色,请将其放在viewDidLoad中

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

要将状态栏文本颜色更改为白色,请将其添加到视图中

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

12
投票

你可能想做几件事。

1)要更改标题的颜色:

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

2)要更改条形按钮的颜色:

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

3)通过整个应用程序使状态栏文本颜色变为白色:

在你的项目plist文件:

  • 状态栏样式:UIStatusBarStyleLightContent
  • 查看基于控制器的状态栏外观:NO
  • 状态栏最初是隐藏的:NO

5
投票

您可以使用以下内容:

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];

3
投票

这就是我做的..

执行以下操作以使状态栏文本颜色在整个应用程序中变为白色。

在你的项目plist文件:

状态栏样式:UIStatusBarStyleLightContent

View controller-based status bar appearance: NO

Status bar is initially hidden: NO

如果你想在整个应用程序中使用相同的行为,则无需实现preferredStatusBarStyle或调用setNeedsStatusBarAppearanceUpdate


3
投票

NSForegroundColorAttributeName替换UITextAttributeTextColor

 self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
© www.soinside.com 2019 - 2024. All rights reserved.