Xcode: Using custom fonts inside Dynamic framework

前端 未结 9 1551
再見小時候
再見小時候 2020-12-04 17:52

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

9条回答
  •  独厮守ぢ
    2020-12-04 18:41

    Found a really easy and readable way to register font, which is not mentioned here:

    func registerFont(with fontName: String) {
        guard let url = Bundle(for: BundleToken.self).url(forResource: fontName, withExtension: nil),
            CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil) else {
                fatalError("Failed to register font: \(font.fileName)")
        }
    }
    
    private final class BundleToken {}
    

提交回复
热议问题