ios - 在 Interface builder 中看到的自定义字体,但在 iOS 项目的代码中看不到

标签 ios swift xcode fonts uifont

我在 iOS 项目中添加了名为“Quicksand_Dash.otf”、“Quicksand-Bold.otf”的自定义字体。我可以在 Interface builder 中看到它,但是当我在代码中列出字体时看不到它。

  • “应用程序提供的字体”和相关名称已添加到 plist 文件。

  • 我检查了字体文件是否在复制包资源中。

Copy Bundle Resources

Ss 2

ss 3

我如何列出字体;

for family in UIFont.familyNames {

        let sName: String = family as String
        print("family: \(sName)")

        for name in UIFont.fontNames(forFamilyName: sName) {
            print("name: \(name as String)")
        }
 }

我可能检查了堆栈溢出中的每个答案,但我认为我遇到了不同的问题。

How To Use Custom Fonts in iPhone SDK

Custom Fonts Not Working

编辑:如果我在 Storyboard 中添加标签并制作其字体 Quicksand。字体也在代码中列出。但是,我不想用户 Storyboard。我在代码中创建 Controller 。

EDIT2:如果我删除 Storyboard 中的标签。又开始不见了。

这与我面临的问题相同,但我已经应用了该帖子中的解决方案;

Custom Font only available in Interface Builder

最佳答案

你会踢自己的......

在你的 plist 信息文件中,你有:

`Quicksand-Dash.otf`

但您添加的文件名为:

`Quicksand_Dash.otf`

下划线不是连字符

重命名您的文件,或编辑 plist 条目,您将看到您的字体。

调试控制台输出:

family: Quicksand
name: Quicksand-BoldItalic
name: QuicksandDash-Regular
name: Quicksand-Bold

这是一个简单的单 View 项目,对我来说效果很好——在模拟器和设备上。 (我没有将字体添加到 OS X,只添加到我的项目):

https://github.com/DonMag/Quicksand

仅供设置引用:

enter image description here

enter image description here

关于ios - 在 Interface builder 中看到的自定义字体,但在 iOS 项目的代码中看不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731043/

相关文章:

ios - Alamofire 模块不使用 Swift 3.0.1 编译

android - 使用 iOS 分布式应用程序时,Google Cloud Messaging 显示 "notRegistered"

ios - 当创建动画使 UIImageView 无限上下(几乎 float )时,如何在动画结束时停止暂停?

ios - StoreKit 的 finishTransaction 崩溃

ios - 按下 UICollectionViewCell 内的按钮会影响其他按钮

ios - Soundcloud iframe 不适用于 UIWebView swift

ios - UIButtons 数组返回错误

xcode - 在基本 block 的中间发现终止符

swift - Swift 和 Spring 中的链接动画无法正常工作

ios - 如何将 xcode 32 位应用程序转换为 64 位 xcode 应用程序