我曾经使用以下代码更改我的应用程序的标题属性(字体、文本颜色等)或导航栏:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];`
今天我刚刚注意到在 iOS8 GM Seed 上,textColor 没有改变,仍然是黑色。
如果有人遇到类似问题并已解决,非常感谢帮助。
最佳答案
UITextAttributeTextColor
已弃用。使用 NSForegroundColorAttributeName
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
更具可读性:
[[UINavigationBar appearance] setTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor whiteColor]}];
在您进入 ViewController 的情况下,按如下方式使用它:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
从外观上看,您必须在 AppDelegate 中使用 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
。
关于ios - UINavigationBar 外观属性不适用于 iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25848371/