gpt4 book ai didi

ios - UIFont 为自定义字体返回 nil

转载 作者:搜寻专家 更新时间:2023-11-01 07:01:21 25 4
gpt4 key购买 nike

我正在尝试使用 Nunito-ExtraBoldItalic我的 UILabel 的字体。

我按照教程和其他答案中列出的步骤进行操作。

  1. 将字体添加到字体文件夹。确保目标设置为项目。 enter image description here
  2. 将条目添加到 plist。 enter image description here
  3. 确保字体显示在构建阶段/复制包资源中。它被显示。

我正在使用以下代码创建一个 UIlabel:

uiLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 160, height: 50))
let myfont = UIFont(name: "Nunito-ExtraBoldItalic", size: 14)
uiLabel!.font = myfont
uiLabel!.textColor = UIColor(red: CGFloat(51/255.0), green: CGFloat(33/255.0), blue: CGFloat(32/255.0), alpha: CGFloat(100.0))
addSubview(uiLabel!)

但是 UIFont 返回 nil。

后记字体名称是“Nunito-ExtraBoldItalic”。

我还尝试运行以下命令:

    for familyName:String in UIFont.familyNames {
print("Family Name: \(familyName)")
for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
print("--Font Name: \(fontName)")
}
}

我的字体没有显示。

该字体在 Storyboard和其他区域中可见。

enter image description here

我尝试使用 Nunito-ExtraBoldItalic、Nunito-ExtraBold Italic、Nunito-ExtraBold-Italic 作为名称。没有工作。

所以我不确定是什么问题。

最佳答案

  1. 将字体文件添加到项目中。

enter image description here

  1. 在Info.plist中添加“应用程序提供的字体”。

    <key>UIAppFonts</key>
    <array>
    <string>CarterOne.ttf</string>
    </array>

  2. 确保字体文件列在 BuildPhase->Copy Bundle Resources 中。

enter image description here

  1. 确保选中目标成员资格。

enter image description here

  1. 执行干净的构建 cmd+option+shift+K

关于ios - UIFont 为自定义字体返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51088003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com