How can I change the font size of a uilabel without changing the font itself?

12,146

Just use the fontWithSize: method on the label's current font:

- (IBAction)setFontSize {
    // Keep the same font but change its size to 24 points.
    UIFont *font = userText.font;
    userText.font = [font fontWithSize:24];
}
Share:
12,146
Dave123
Author by

Dave123

Updated on June 04, 2022

Comments

  • Dave123
    Dave123 almost 2 years

    I'm having an issue where I allow the user to select a font for a label in my project, but then when the user sets the size of that label (using a different button), the label resets to a default font. I'd like to be able to retain the font that the user had applied while still allowing the user to change the font size. Any help is appreciated, thanks!

    Here's my code..

    -(IBAction)setFont{
    
        [userText setFont:[UIFont fontWithName:@"Arial-BoldMT" size:50.0]];
    
    //I had to add a size when setting the font or else I got an error
    
    
    }
    
    
    
    -(IBAction)setFontSize{
    
      [userText setFont:[UIFont systemFontOfSize:24]];
    
    }