Search code examples
swiftuilabelappdelegateuifontuiappearance

Changing UILabel's size changes its font name


I wanted to change the default font of the app so I did

UILabel.appearance().font = UIFont(name: "PartyLetPlain", size: 17)

in the AppDelegate and it worked as expected until I tried to change the font size.

I tried changing the font size like so

categoryName.font = UIFont(name: categoryName.font.fontName, size: 17)

or categoryName.font.fontWithSize(20)

After changing the font sizes it changes the fontName and it printed this font name .SFUIText so just for a change I commented the

UILabel.appearance().font = UIFont(name: "PartyLetPlain", size: 17)

from the AppDelegate and changed the font from storyboard and worked well even after changing the font size.

How to solve this issue?


Solution

  • .SFUIText is the default system font hence you are getting the same result when you are assigning.

    Appearance does not change the properties once they are in the window. Create custom label class and use it.

    Or simply use your font UIFont(name: "PartyLetPlain", size: 17) to change the font size. it will work.

    For appearance please check link https://developer.apple.com/reference/uikit/uiappearance