-3

My task is to white label iOS application.

I've done a lot of things for Assets and for Info.plist, I just left to manage a white-label solution for the fonts.

For example, Every customer wants to have their fonts for titles. So I got in my mind some solutions.

1) There will be some Config files we can write customers fonts in the config file and when Application will run I will read font from that config file and apply them but didn't know how to to that on every screen dynamically.

2) Create some base ViewController class and apply here fonts, then every viewController class will be the child of that base class and apply view controllers specific title fonts to my base fonts.

I don't know if those solutions are good and the reason for this question is to get some advice and some better solutions.

Maybe someone is more experienced than me and maybe someone has a better idea than me. Every single advice and help will be very valuable for me.

Thank you.

Tornike Gomareli
  • 1,564
  • 2
  • 16
  • 28

1 Answers1

1

What I normally do in these cases is, create a extension for Font class have a look:

extension UIFont {
    open class func boldAppFont(ofSize size:CGFloat) -> UIFont {
        guard let f = UIFont(name: KTheme.FontName.bold, size: size)
        else {
            return UIFont.boldSystemFont(ofSize: size)
        }
        return f
    }

    open class func blackAppFont(ofSize size:CGFloat) -> UIFont {
        guard let f = UIFont(name: KTheme.FontName.black, size: size)
            else {
                return UIFont.boldSystemFont(ofSize: size)
        }
        return f
    }
}

Now you can change KTheme.FontName.bold to your font name and pass that in your request. Just make sure to set the font for each component using this function.

You can also use appearance to make a global effect.

Now let's come to the next problem. You can only supply a limited amount of font inside your application. As in order to use a custom font your application info.plist must be aware of those fonts.

How to add fiont in info.plist

What I will suggest in that case bundle set of fonts and ask the user to choose among those. While he selects the custom font.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
  • I don't understand what you mean with the info.plist part? – Chucky May 07 '21 at 14:12
  • I don't think this can be used in a white label app as you could have any number of possible fonts to cater for. Have a look at this answer https://stackoverflow.com/questions/30412068/using-custom-font-without-including-in-info-plist-ios – Chucky May 07 '21 at 15:29