Search code examples
iosobjective-cfontsnsattributedstring

iOS - UILabel attributedText in IB not able to change font size


In interfaceBuilder i have created a simple UILabel. It has text inside and i set it to attributedText. I'm not able to change the font size. Each time i try to change the font and run the program the font remains unchanged. In fact what i have tried is after i alter the font size and run the app and return to IB the font has been reset on its own !!

here are my IB settings for UILabel attributedText:

enter image description here


Solution

  • Try this:

    yourlabel.font = [yourlabel.font fontWithSize:16];
    

    or

    [yourlabel setFont:[UIFont systemFontOfSize:16]];
    

    Setting the font size is better done in your code, typically in viewWillAppear or viewDidLoad methods.

    This link --> HERE <-- has another way by creating a method to handle changing font size in attributed text. Not bad either.