views:

346

answers:

2

I have initialized a text box to have font size 16. Now I have noticed that as I type beyond the boundary of the text box, iPhone decreases the font size and then scrolls. Now If I delete everything from the text box and start typing, it starts with the small font and never becomes 16. Could you let me know how can I fix this? Can I initialize the font size at some method every time somebody starts typing?

Thanks.

+3  A: 

I think you have it setup so that text field adjust font size to fit the text inside. Try not setting it or reset to what you require.

UITextField reference:

adjustsFontSizeToFitWidth

A Boolean value indicating whether the font size should be reduced in order to fit the text string into the text field’s bounding rectangle.

@property(nonatomic) BOOL adjustsFontSizeToFitWidth

Discussion

Normally, the text field’s content is drawn with the font you specify in the font property. If this property is set to YES, however, and the contents in the text property exceed the text field’s bounding rectangle, the receiver starts reducing the font size until the string fits or the minimum font size is reached. The text is shrunk along the baseline.

The default value for this property is NO. If you change it to YES, you should also set an appropriate minimum font size by modifying the minimumFontSize property.

stefanB
+1  A: 

In Interface Builder, if you select the text field, you can deselect the 'Adjust to Fit' checkbox in the TextField Attributes. The font should remain the same as you set it and will show an elipsis (50...) if the content exceeds the space available.

Chris Brandt