ios - 在 Swift 中带有 ttf 文件的字形

标签 ios swift unicode

我正在尝试将 ttf 文件用于 iOS 应用程序的字形,但字体字符串存在一些问题...我可以从 ttf 文件中读取 unicode 字体,但似乎没有从中读取字形文件。

例如,以下代码适用于 unicode 字符。

let myFont = UIFont(name: "WeatherIcons-Regular", size: 15)
cell.detailTextLabel?.font = myFont
cell.detailTextLabel?.text = "\u{26c8}"

但是,如果我尝试阅读一个字形,图标会显示为一个问号,周围有一个框。

let myFont = UIFont(name: "WeatherIcons-Regular", size: 15)
cell.detailTextLabel?.font = myFont
cell.detailTextLabel?.text = "\u{f001}"

链接到下面的 ttf 文件和 css 文件。

我已将字体文件添加到我的应用程序中。 font added to plist

最佳答案

让你在 iOS 项目的 Info.plist 中添加“Fonts provided by application”(即 UIAppFonts)键,并添加项目“weathericons-regular-webfont.ttf”。

UIAppFonts (Array - iOS) Specifies any app-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the app’s bundle. The system loads the specified fonts and makes them available for use by the app when that app is run.

像这样:

Fonts provided by application

用Font Book app打开字体文件,可以看到字体名称为“Weather Icons”。然后打印所有字体名称以检查字体是否可用:

print(UIFont.familyNames())

关于ios - 在 Swift 中带有 ttf 文件的字形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33480719/

相关文章:

ios - iPhone 应用程序的 JSONKit?

ios - Hook 任何事件并计算时间执行

swift - 滚动时导航栏标题发生变化

unicode - Twitter bootstrap 使用的关闭符号的 unicode 字符是什么?

ios - NSString大小不考虑希腊呼吸痕

python - 清理推文的问题(表情符号、笑脸......)

ios - 如何以编程方式设置 UITableView header 的约束以同时支持 RTL 和 LTR?

ios - 动画 UIScrollView contentInset 导致跳转卡顿

objective-c - Swift 与 ARC 之前的 Objective-C 不兼容吗?

ios - 如果修改了任何属性值,则更改数组内所有属性的值 swift (wiiSet)