Xcode: Using custom fonts inside Dynamic framework

前端 未结 9 1581
再見小時候
再見小時候 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:26

    The following solution allows you to load all fonts with a certain extension automatically:

    static func registerFonts() {
        let fonts = Bundle(for: 
    OrientationMonitor.self).urls(forResourcesWithExtension: "ttf", subdirectory: nil)
        fonts?.forEach({ url in
            CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)
        })
    }
    

    Make sure to replace OrientationMonitor with a class existing in your framework.

提交回复
热议问题