Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS7导航栏文本颜色_Iphone_Ios7 - Fatal编程技术网

Iphone iOS7导航栏文本颜色

Iphone iOS7导航栏文本颜色,iphone,ios7,Iphone,Ios7,我在将文本和状态栏文本颜色更改为白色时遇到问题 我希望所有的黑色文字都是白色的,有什么想法吗 我见过很多解决方案,但似乎没有一个能在iOS 7上工作。要将标题文本颜色变为白色,请将其放入viewDidLoad self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : [UIColor whiteColor]} 要将状态栏文本颜色更改为白色,请将其添加到视图中 [[UIAp

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

我希望所有的黑色文字都是白色的,有什么想法吗


我见过很多解决方案,但似乎没有一个能在iOS 7上工作。要将标题文本颜色变为白色,请将其放入viewDidLoad

self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor : [UIColor whiteColor]}
要将状态栏文本颜色更改为白色,请将其添加到视图中

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
我就是这么做的

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

在您的项目上
plist
文件:

状态栏样式:
UIStatusBarStyleLightContent

查看基于控制器的状态栏外观:否

状态栏最初隐藏:否


如果您希望在整个应用程序中实现相同的行为,则无需实施
preferredStatusBarStyle
或调用
setNeedsStatusBarAppearanceUpdate

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

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

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

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
在中,您可以使用
UINavigationBarAppearance
设置导航栏本身的外观:

let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

navigationBar.standardAppearance = appearance

你可能想做几件事

1) 要更改标题的颜色,请执行以下操作:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
2) 要更改工具栏按钮的颜色,请执行以下操作:

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
3) 要使状态栏文本在整个应用程序中变为白色,请执行以下操作:

在您的项目plist上文件:

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

您可以使用以下功能:

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

只需将NSForegroundColorAttributeName替换为UITextAttributeText颜色即可

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

很好,第一部分工作正常,但我必须将其更改为:self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor]};但第二部分不起作用。我是否要添加到AppDelegate.m?您应该将其添加到viewControllers的didLoad或WILLEXPEND方法中。您可能还需要调用[self-setNeedsStatusBarAppearanceUpdate]。你也可以在你的信息中更改状态栏的外观。谢谢。这救了我一天!:)我已将其添加到MasterViewController.m viewDidLoad中,但状态栏文本仍然为黑色。必须将ViewControllerBasedStatusBarApperance设置为“是”(这是默认设置)。如果是这种情况,则需要在每个ViewController中覆盖-(UIStatusBarStyle)preferredStatusBarStyle。如果要在状态中查找白色文本,请确保返回UIStatusBarStyleLightContent。这是升级在xcode 4.6.3中构建的项目所需要做的。新的xcode 5项目的默认设置似乎没有更新到通常的状态,这已经解决了这个问题。这对导航栏标题文本颜色没有帮助