I added custom font to a framework. I followed all the steps, but it doesn\'t work.
I am able to set the font in Interface Builder, but when I build the project it d
I made a mix of different answers in Swift 4.2 so props to the guys who came up with it!
import UIKit
import Foundation
extension UIFont {
private class MyDummyClass {}
static func loadFontWith(name: String) {
let frameworkBundle = Bundle(for: MyDummyClass.self)
let pathForResourceString = frameworkBundle.path(forResource: name, ofType: "ttf")
let fontData = NSData(contentsOfFile: pathForResourceString!)
let dataProvider = CGDataProvider(data: fontData!)
let fontRef = CGFont(dataProvider!)
var errorRef: Unmanaged? = nil
if (CTFontManagerRegisterGraphicsFont(fontRef!, &errorRef) == false) {
NSLog("Failed to register font - register graphics font failed - this font may have already been registered in the main bundle.")
}
}
public static let loadMyFonts: () = {
loadFontWith(name: "Exo-Black")
loadFontWith(name: "Exo-Bold")
loadFontWith(name: "Exo-Regular")
}()
}
And then call in Appdelegate
UIFont.loadMyFonts