简体   繁体   English

如何在Swift中重用字体?

[英]How to reuse fonts in Swift?

Imagine I have this custom font font.ttf 假设我有此自定义字体font.ttf

And I have two projects. 我有两个项目。 Project A in /projects/A and project B in /projects/B /projects/A A中的/projects/A/projects/B

I don't want to copy paste this font among projects. 我不想在项目之间复制粘贴此字体。

I created a cocoa touch framework and added the font.ttf to that. 我创建了一个可可触摸框架,并在其中添加了font.ttf Then reused that framework in projects A and B. But it doesn't work. 然后在项目A和B中重用该框架。但是它不起作用。 Is it possible? 可能吗?

According to this thread , you can try 根据这个线程 ,你可以尝试

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)
}

// //

在此处输入图片说明

// //

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM