8

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.

Adam Wenger
  • 17,100
  • 6
  • 52
  • 63
Hanon
  • 3,917
  • 2
  • 25
  • 29

1 Answers1

34
myLabel.adjustsFontSizeToFitWidth = YES;

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

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

Sanjay Chaudhry
  • 3,181
  • 1
  • 22
  • 31
  • 1
    Since I want to let user to pinch the size as they want, I set the font size to 300 when it init. But the text seems not smooth when the label is small. The code I have: [label setText:text]; [label setTextColor:color]; [label setFont:font];// font has setup to size 300 [label setNumberOfLines:1]; [label setMinimumFontSize:5]; [label setAdjustsFontSizeToFitWidth:YES]; – Hanon Nov 21 '11 at 05:33
  • 1
    Obviously there would be some limit of fonts. After some level it wont be that much smoother as they look in normal view. Otherwise i do agree with Sanjay's answer. I guess that is the only way. – Mrunal Nov 21 '11 at 14:56