Can I embed a custom font in a bundle and access it from an ios framework?

后端 未结 7 1326
北荒
北荒 2020-12-13 02:35

I\'m creating an ios framework with its bundle for packaging ressources (nib, images, fonts) and I\'m trying to embed a custom font

7条回答
  •  没有蜡笔的小新
    2020-12-13 03:09

    You can use this extension if you have the font in a file/bundle.

    public extension UIFont {
    
        static func register(from url: URL) throws {
            if !FileManager.default.fileExists(atPath: url.path) {
                throw VError.incorrectFont
            }
    
            var error: Unmanaged?
    
            guard CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error) else {
                throw error!.takeUnretainedValue()
            }
        }
    }
    

提交回复
热议问题