Change textColor of UINavigationBar “prompt”?

2019-05-07 06:22发布

问题:

Any (supported) way of doing this? IIRC it usually switches over by itself to a white color at some point when using a "darker than X" tintColor, but we seem to be just on the edge with our scheme.

回答1:

I guess the only way to really do it is to use a custom titleView for each UINavigationItem. You can use a UILabel and try to match the built-in navigation title style as closely as you can, then assign your own text color.



回答2:

It's possible in iOS5:

[[UINavigationBar appearance] setTitleTextAttributes:
      [NSDictionary dictionaryWithObjectsAndKeys:
       [UIColor whiteColor], UITextAttributeTextColor, nil]];


回答3:

And for iOS 7 you can make this to set the prompt to White Color. Please note that it will also change the color of the navbar title.

[[[self navigationController] navigationBar] setTitleTextAttributes:
  @{NSForegroundColorAttributeName:[UIColor whiteColor]}];