在Swift中更改大型标题导航栏的字体

Rya*_*yan 0 uinavigationbar navigationbar swift preferslargetitles

如何在Swift中更改大标题导航栏的字体?

我无法找到涵盖实现带有大标题的导航栏的自定义字体的线程。

我正在尝试使用标题为“ ??????????? W8.ttc”的字体。这似乎已预装在我的Mac上。字体书中的名称是:“ Hiragino Kaku Gothic StdN”。

这是我尝试过的:

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "???????????-W8", size: 20)!]
Run Code Online (Sandbox Code Playgroud)

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "???????????W8", size: 20)!]
Run Code Online (Sandbox Code Playgroud)

self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Hiragino Kaku Gothic StdN", size: 20)!]
Run Code Online (Sandbox Code Playgroud)

字形 “ W8”是该字体的加粗版本。

字体文件名使用其他语言还是其他问题?

vij*_*har 6

请检查图像 如何在<code> info.plist </ code>中添加字体

拳头确保您的字体是.ttf或.otf格式

1)将字体导入项目2)在应用程序的info.plist文件上添加新键“应用程序提供的字体” 并添加字体名称现在,您可以将自定义字体与界面生成器一起使用,也可以以编程方式使用

navigationController?.navigationBar.largeTitleTextAttributes =
    [NSAttributedStringKey.foregroundColor: UIColor.blue,
     NSAttributedStringKey.font: UIFont(name: "your font name", size: 30) ??
                                 UIFont.systemFont(ofSize: 30)]
Run Code Online (Sandbox Code Playgroud)