当我第一次打开应用程序时,我的导航栏字体也不会改变我的自定义字体,但是当我转到另一页面并返回页面时,字体会发生变化。有关如何修复导航栏字体始终是正确字体的任何想法吗?
我的自定义字体当我点击页面然后回到此页面时,字体更新了。
这是我的App代码,如下所示。任何帮助都会很棒:)
let navigationFont = UIFont(name: "MuseoSansRounded-900", size: 17)!
let navigationLargeTitleFont = UIFont(name: "MuseoSansRounded-900", size: 34)!
let navigationFontAttributes = [kCTFontAttributeName : navigationFont]
let navigationLargeFontAttributes = [kCTFontAttributeName : navigationLargeTitleFont]
UINavigationBar.appearance().titleTextAttributes = navigationFontAttributes as [NSAttributedStringKey : Any]
UINavigationBar.appearance().largeTitleTextAttributes = navigationLargeFontAttributes as [NSAttributedStringKey : Any]
UIBarButtonItem.appearance().setTitleTextAttributes(navigationFontAttributes as [NSAttributedStringKey : Any], for: .normal)
我已经解决了这个问题。我在应用程序委派上移动了更高的代码,当我第一次来到页面时,字体正在改变。更新后的代码如下。感谢大家的帮助!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// NAV BAR COLOR FOR ALL THE NAVS AND THE FONTS BELOW.
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().barTintColor = .white
UINavigationBar.appearance().tintColor = blackSupportalColor
// Navigation Bar Font Below
let navigationFont = UIFont(name: "MuseoSansRounded-900", size: 17)!
let navigationLargeTitleFont = UIFont(name: "MuseoSansRounded-900", size: 34)!
let navigationFontAttributes = [kCTFontAttributeName : navigationFont]
let navigationLargeFontAttributes = [kCTFontAttributeName : navigationLargeTitleFont]
UINavigationBar.appearance().titleTextAttributes = navigationFontAttributes as [NSAttributedStringKey : Any]
UINavigationBar.appearance().largeTitleTextAttributes = navigationLargeFontAttributes as [NSAttributedStringKey : Any]
UIBarButtonItem.appearance().setTitleTextAttributes(navigationFontAttributes as [NSAttributedStringKey : Any], for: .normal)
答案 0 :(得分:0)
这通常是因为你没有将它们包含在你的Xcode项目中。
您可以点击此链接,告诉您如何添加它们:https://medium.com/yay-its-erica/how-to-import-fonts-into-xcode-swift-3-f0de7e921ef8
该指南适用于 Swift 3 ,但Xcode 9的过程仍然相同。
答案 1 :(得分:0)
我已经解决了这个问题。我在应用程序委派上移动了更高的代码,当我第一次来到页面时,字体正在改变。更新后的代码如下。感谢大家的帮助!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// NAV BAR COLOR FOR ALL THE NAVS AND THE FONTS BELOW.
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().barTintColor = .white
UINavigationBar.appearance().tintColor = blackSupportalColor
// Navigation Bar Font Below
let navigationFont = UIFont(name: "MuseoSansRounded-900", size: 17)!
let navigationLargeTitleFont = UIFont(name: "MuseoSansRounded-900", size: 34)!
let navigationFontAttributes = [kCTFontAttributeName : navigationFont]
let navigationLargeFontAttributes = [kCTFontAttributeName : navigationLargeTitleFont]
UINavigationBar.appearance().titleTextAttributes = navigationFontAttributes as [NSAttributedStringKey : Any]
UINavigationBar.appearance().largeTitleTextAttributes = navigationLargeFontAttributes as [NSAttributedStringKey : Any]
UIBarButtonItem.appearance().setTitleTextAttributes(navigationFontAttributes as [NSAttributedStringKey : Any], for: .normal)