ios - UINavigationBar 外观属性不适用于 iOS 8

标签 ios uinavigationbar ios8

我曾经使用以下代码更改我的应用程序的标题属性(字体、文本颜色等)或导航栏:

[[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/

相关文章:

ios - Swift - 使用 NSExpression 分配 UILabel

ios - 阴影图像在第一个 viewWillAppear 上不起作用

ios - 选项卡式 UINavigationBar iOS 8

ios - 如何导出在设备中为 Xcode 6 创建的文件?

ios - iPhone 6 和 6 plus 给出错误的帧、边界值

ios - 为什么归一化后的目标检测结果中存在负坐标? (CoreML、Vision、Swift、Ios)

ios - 如何根据 Intent 类型在 Sirikit 扩展中推送不同的 IntentViewController?

iOS 在后台下载图像并更新 UI

ios - UIBarButtonItem 改变 viewController 的方向

ios - iCloud Key-Value-Store 同步问题(未调用 NSUbiquitousKeyValueStoreDidChangeExternallyNotification)