Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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]];

}
like image 492
Dave123 Avatar asked May 20 '13 02:05

Dave123


People also ask

How do you change the font size in UILabel?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.

How do I stop system font size changing effects to Android application?

You cannot stop the user from changing the system font size; you'll just have to use dp and ignore the lint errors!


1 Answers

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];
}
like image 200
rmaddy Avatar answered Oct 19 '22 09:10

rmaddy