UINavigationBar外观属性在iOS 8上不起作用

ris*_*abh 0 uinavigationbar ios ios8

我曾经使用下面的代码更改我的应用程序的标题属性(font,textColor等)或Nativgation Bar:

[[UINavigationBar appearance] setTitleTextAttributes: 
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil]];`
Run Code Online (Sandbox Code Playgroud)

今天我注意到在iOS8 GM Seed上,textColor没有变化,仍然是黑色.

如果有人遇到过类似的问题并得到解决,那么非常感谢.

Mat*_*atz 6

UITextAttributeTextColor已弃用.使用NSForegroundColorAttributeName

[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
Run Code Online (Sandbox Code Playgroud)

更具可读性:

[[UINavigationBar appearance] setTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor whiteColor]}];
Run Code Online (Sandbox Code Playgroud)

在你进入ViewController的情况下使用它如下:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes: @{NSForegroundColorAttributeName: [UIColor whiteColor]}];
}
Run Code Online (Sandbox Code Playgroud)

随着外观你必须采取- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 内部AppDelegate.