Ali Fallah
Ali Fallah

Reputation: 753

How to reuse fonts in Swift?

Imagine I have this custom font font.ttf

And I have two projects. Project A in /projects/A and project B in /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. Then reused that framework in projects A and B. But it doesn't work. Is it possible?

Upvotes: 4

Views: 240

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

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

//

enter image description here

//

enter image description here

Upvotes: 1

Related Questions