ios - UINavigationBar 上的自定义字体不起作用

标签 ios swift2 uinavigationbar

我不知道为什么这不起作用,我已经用许多有效的字符串尝试过(顺便说一下,cFont = "Courier"但我已经尝试过 "Chalkduster"和其他一些来测试),颜色正确以上是工作,但字体不是。有任何想法吗?

函数就在 AppDelegate 中的 didFinishLaunchingWithOptions 下面。

func setUpAppearance() {

//Work fine

    window?.tintColor = Colors().navBackgroundColor

    UINavigationBar.appearance().barTintColor = Colors().navBackgroundColor
    UINavigationBar.appearance().tintColor = Colors().navTextColor

//Doesn't work

    UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: cFont, size: 24)!]

}

谢谢你的帮助

最佳答案

明白了!没有意识到我必须为栏按钮项以及 NSForeGroundColorAttributeName 添加一个单独的实例。

更新后的函数工作正常...

func setUpAppearance() {

    window?.tintColor = Colors().navBackgroundColor

    UINavigationBar.appearance().barTintColor = Colors().navBackgroundColor
    UINavigationBar.appearance().tintColor = Colors().navTextColor

    UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: cFont, size: 24)!, NSForegroundColorAttributeName: Colors().navTextColor]

    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: cFont, size: 24)!, NSForegroundColorAttributeName: Colors().navTextColor], forState: .Normal)

}

关于ios - UINavigationBar 上的自定义字体不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37445889/

相关文章:

ios - 为 iOS 构建时,开发团队没有出现错误

string - 如何在 Swift 2.0 中为 URL 使用 stringByAddingPercentEncodingWithAllowedCharacters()

swift2 - UICollectionView : Programmatically moving focus from one view to another - tvOS

ios - 单元格不可在主视图中嵌入 UItableView?

ios - iPhone 导航栏标题文本颜色在 iOS 11 中的 viewWillAppear() 或 viewWillDisappear 函数中不会改变

ios - 导航栏按钮图片

iOS UINavigationBar 按钮在 segue 返回后仍然褪色

iphone - The Amazing Audio Engine AERecorder 不录音

ios - 如何在特定索引处更改标签的颜色?

web-services - 将哪个框架集成到我的项目中以使用 Web 服务