Change default font to custom fonts in whole app

前端 未结 6 1980
猫巷女王i
猫巷女王i 2020-12-30 16:54

I want to keep custom fonts in iOS app. Currently, I\'m using iOS default fonts. Is there any possible way for the same?

How do I include the custom font so that I c

6条回答
  •  [愿得一人]
    2020-12-30 17:01

    Ok, from all the other answers you are now very well familier that how to add a custom font (other than iOS default font) into app.

    So now what? One thing is still remaining, I'm not sure if you want to use the same size custom font everywhere. If so,

    I'm using this way to have custom font in my app.

    If your app will have a single custom font then you can use it like this way for entire app.

    #define appFontBold(x) [UIFont fontWithName:@"CustomFont-Bold" size:x]
    #define appFontLight(x) [UIFont fontWithName:@"CustonFont-Light" size:x]
    #define appFontRegular(x) [UIFont fontWithName:@"CustonFont-Regular" size:x]
    

    I've added these macros globally (so can access it from anywhere)

    and you can use it like this, yourLabel.font = appFontRegular(12); or yourTextField.font = appFontBold(14); this helps you in following situations,

    1. Whenever you needs to change the custom font, you only need to change font name in macros.
    2. Your code will looks clean, no need write [UIFont fontWithName: size:]; everywhere.

    If your app will have more than one custom font then you can use it like this way for entire app.

    then also you can define different macros like this,

    Then above macro will be the same (as this is the maximum used fonts in app), for other fonts :

    #define appFontBoldOtherFont(x) [UIFont fontWithName:@"CustomOtherFont-Bold" size:x]
    #define appFontLightOtherFont(x) [UIFont fontWithName:@"CustonOtherFont-Light" size:x]
    #define appFontRegularOtherFont(x) [UIFont fontWithName:@"CustonOtherFont-Regular" size:x]
    

提交回复
热议问题