Xcode: Using custom fonts inside Dynamic framework

Vojtech Vrbka

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 doesn't show this font on the simulator/device.

John Bushnell

I'm here a bit late, but I took PetahChristian's solution and created a Swift version in the form of an extension. This is working for me. I've found that when you try to get a font using a font name and a size using the regular way that it always looks in the main bundle for the font file, and there's no method that takes a bundle identifier as a parameter. It would be nice if Apple would make one.

Swift:

public extension UIFont {

    public static func jbs_registerFont(withFilenameString filenameString: String, bundle: Bundle) {

        guard let pathForResourceString = bundle.path(forResource: filenameString, ofType: nil) else {
            print("UIFont+:  Failed to register font - path for resource not found.")
            return
        }

        guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
            print("UIFont+:  Failed to register font - font data could not be loaded.")
            return
        }

        guard let dataProvider = CGDataProvider(data: fontData) else {
            print("UIFont+:  Failed to register font - data provider could not be loaded.")
            return
        }

        guard let font = CGFont(dataProvider) else {
            print("UIFont+:  Failed to register font - font could not be loaded.")
            return
        }

        var errorRef: Unmanaged<CFError>? = nil
        if (CTFontManagerRegisterGraphicsFont(font, &errorRef) == false) {
            print("UIFont+:  Failed to register font - register graphics font failed - this font may have already been registered in the main bundle.")
        }
    }

}

Usage Example:

UIFont.jbs_registerFont(
    withFilenameString: "Boogaloo-Regular.ttf",
    bundle: Bundle(identifier: "com.JBS.JBSFramework")!
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using custom fonts in Xcode 6 - Swift

From Dev

Custom Fonts in Xcode 5

From Dev

Swift Custom Fonts Xcode

From Dev

Custom Fonts in Xcode 5

From Dev

Installing custom fonts in Xcode 4.6.3

From Dev

custom fonts in xcode 7 and adaptive layout

From Dev

Using Custom Fonts Properly in Android

From Dev

Document custom Framework XCode

From Dev

Custom fonts for TextView based on languages inside String

From Dev

linking custom framework to library in xcode

From Dev

Using custom OTF fonts in ggplot2

From Dev

Using custom fonts with Google Web Toolkit

From Dev

Correctly using custom fonts in separate .css stylesheet

From Dev

Custom fonts in CSS using font-face

From Dev

Using Web Fonts in Custom SharePoint MasterPage HTML

From Dev

Using custom fonts and recoloring for MapboxGl markers

From Dev

Using custom fonts without administrator rights?

From Dev

Using Realm in a dynamic framework?

From Dev

Using Realm in a dynamic framework?

From Dev

fontWithName returns nil for custom fonts after updating to Xcode 5.1.1

From Dev

Custom fonts working in Interface Builder (Xcode 6), but not a device

From Dev

Custom fonts with CCLabelTTF on Cocos2d-x (XCode) not working

From Dev

changing custom font for UILabel using custom fonts (programatically) in swift

From Dev

Ionic Framework display dynamic value inside $ionicLoading

From Dev

Play Framework, Dynamic statement inside for loop

From Dev

Edit custom path with OpenCV framework using CMake to generate XCODE project in iOS

From Dev

Edit custom path with OpenCV framework using CMake to generate XCODE project in iOS

From Dev

Using dynamic library in static framework or using static library in dynamic framework

From Dev

Using dynamic models in Django framework

Related Related

  1. 1

    Using custom fonts in Xcode 6 - Swift

  2. 2

    Custom Fonts in Xcode 5

  3. 3

    Swift Custom Fonts Xcode

  4. 4

    Custom Fonts in Xcode 5

  5. 5

    Installing custom fonts in Xcode 4.6.3

  6. 6

    custom fonts in xcode 7 and adaptive layout

  7. 7

    Using Custom Fonts Properly in Android

  8. 8

    Document custom Framework XCode

  9. 9

    Custom fonts for TextView based on languages inside String

  10. 10

    linking custom framework to library in xcode

  11. 11

    Using custom OTF fonts in ggplot2

  12. 12

    Using custom fonts with Google Web Toolkit

  13. 13

    Correctly using custom fonts in separate .css stylesheet

  14. 14

    Custom fonts in CSS using font-face

  15. 15

    Using Web Fonts in Custom SharePoint MasterPage HTML

  16. 16

    Using custom fonts and recoloring for MapboxGl markers

  17. 17

    Using custom fonts without administrator rights?

  18. 18

    Using Realm in a dynamic framework?

  19. 19

    Using Realm in a dynamic framework?

  20. 20

    fontWithName returns nil for custom fonts after updating to Xcode 5.1.1

  21. 21

    Custom fonts working in Interface Builder (Xcode 6), but not a device

  22. 22

    Custom fonts with CCLabelTTF on Cocos2d-x (XCode) not working

  23. 23

    changing custom font for UILabel using custom fonts (programatically) in swift

  24. 24

    Ionic Framework display dynamic value inside $ionicLoading

  25. 25

    Play Framework, Dynamic statement inside for loop

  26. 26

    Edit custom path with OpenCV framework using CMake to generate XCODE project in iOS

  27. 27

    Edit custom path with OpenCV framework using CMake to generate XCODE project in iOS

  28. 28

    Using dynamic library in static framework or using static library in dynamic framework

  29. 29

    Using dynamic models in Django framework

HotTag

Archive