Xcode: self-adjusting font size depending on how a much text is in a text field

3.3k Views Asked by At

I have created a UIlabel and UItextfield that correspond with each other. My new challenge is to have my font self-adjust its size to fill the UIlabel depending on how much text is entered. Solutions?

1

There are 1 best solutions below

0
On

UILabel has a property adjustsFontSizeToFitWidth. Please refer to UILabel Class Reference.

UITextField has a same one, see UITextField Class Reference.

You can set a big enough default font size and let the control reduce the text to fit the width. The actual font size will be between minimumFontSize and the size setting of font.