ios – 如何在Swift中重用字体?

前端之家收集整理的这篇文章主要介绍了ios – 如何在Swift中重用字体?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
想象一下,我有这个自定义字体
    font.ttf

我有两个项目. / projects / A中的项目A和/ projects / B中的项目B.

我不想在项目中复制粘贴此字体.

我创建了一个可可触摸框架并添加了font.ttf.然后在项目A和B中重用该框架.但它不起作用.可能吗?

解决方法

根据这个 thread,你可以试试

let bundle = Bundle(identifier: "frameworkIdentifier")!

let url =  bundle.url(forResource: "fontName",withExtension: "ttf")!

if let dataProvider = CGDataProvider(url: url as CFURL) {
    let font = CGFont(dataProvider)
    print(font)
}

//

enter image description here

//

enter image description here

猜你在找的Xcode相关文章