我正在尝试将 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 文件。
最佳答案
让你在 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.
像这样:
用Font Book app打开字体文件,可以看到字体名称为“Weather Icons”。然后打印所有字体名称以检查字体是否可用:
print(UIFont.familyNames())
关于ios - 在 Swift 中带有 ttf 文件的字形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33480719/