Reputation: 95
I had a custom font created and I'm using it in my application built in swiftui.
Since they liked the font, I would like to use it not only in the application but also on all the iPhones and iPads that have my application installed. I searched the internet a bit and came up with this:
Most importantly I understood that I have to use this class CTFontManagerRegisterGraphicsFont. But I don't understand how to use it.
Many tutorials show how to use a font in your application but none ever share the imported fonts with the device.
How can I go on? I also searched this site but couldn't find anything. Please don't report it as a DUPLICATE POST
Upvotes: 0
Views: 271
Reputation: 95
I found the solution to my problem. I hope it is useful to others.
var fontUrl = Bundle.main.url(forResource: "MyCustomFont", withExtension: "ttf")
//I apply the registration
registerFont(fontUrl: fontUrl!)
.....
private func registerFont(fontUrl : URL){
CTFontManagerRegisterFontURLs([fontUrl] as CFArray, .persistent, true) { (errors, done) -> Bool in
if(done) {
print("Done")
}
print(errors as Array)
return true
}
}
When you run the application you will get the pop up to install the font.
At this point: Settings > General > Font You will find the font
Upvotes: 1