Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UILabel font size according to its frame size?

I have an application that allow user to use the pinch gesture for scaling the label How can I change the font size according to the new frame size so that the font just fit in the frame rectangle?

My current step is only set the label with new transform, and the text will look blur if the label is scaled too small/large. I want to ensure that the label can display the text clearly where the text can have the max size according to the new frame rectangle.

like image 753
Hanon Avatar asked Nov 21 '11 05:11

Hanon


People also ask

How do you change the font size on 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.

What is Minimumscalefactor?

Sets the minimum amount that text in this view scales down to fit in the available space.


1 Answers

myLabel.adjustsFontSizeToFitWidth = YES;

If you're using InterfaceBuilder, check "Autoshrink" for the label.

Make sure that "Minimum Size" is not too large.

like image 68
Sanjay Chaudhry Avatar answered Oct 16 '22 16:10

Sanjay Chaudhry