UITextfield text moves through editing

When my UITextField becomes the first responder (when editing), the text moves very slowly, and the distance between characters increases very slightly. After canceling the first responder (the keyboard leaves), the characters return to their original positioning. At first I thought it was a font problem since I use my own font, but the same thing happens when I use a system font or other custom fonts.

Please check the images below. The first is with the keyboard down, and the second with the keyboard up. This can be difficult to see, since the variance is small, but the state at the top of the keyboard indicates that the characters are slightly moved down.

enter image description here

enter image description here

+14
ios objective-c iphone uikit xcode
Aug 31 '13 at 0:06
source share
7 answers

Selecting the "adjust to fit" property sets the adjustsFontSizeToWidth property to UITextField.

This property has ( UITextField Apple Documentation ):

Typically, the contents of text fields are drawn in the font specified in the font property. If this property is set to "YES" and the content in the text property exceeds the bounding text box rectangle, the receiver begins to reduce the font size until the line fits or the minimum font size. The text is cut along the base level.

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

I would try to uncheck this checkbox first and see if it stops it, then follow the documentation advice and otherwise set the minimumFontSize property below, which may also cause a problem.

This problem may be due to the appearance of a blue “now editing” cursor. The source text ( link ) is the bottom of the text. Your text shrinks “along the baseline” by clicking down, which tends to lean more in the direction that is the problem of minimumFontSize / adjustsFontSizeToWidth.

+2
Aug 31 '13 at 1:28
source share

In xib, set the textfield borderStyle to a value other than TextBorderStyleNone. And in the code, set the borderStyle text field as TextBorderStyleNone explicitly.

I could not understand why, but it seems like an initialization error. It works fine in other code that does not initialize a UITextField via xib exit.

When setting the borderStyle text field as TextBorderStyleNone in xib, the problem persists even if the borderStyle parameter is set to TextBorderStyleNone in the code. It may be followed by some layoutIfNeeded material caused by a change in value.

+2
Dec 09 '16 at 6:56
source share

Checking OFF the "Clip to Borders" textField in my storyboard is great for me.

+2
Jan 24 '17 at 8:23
source share

If you force to create the first UITextField responder, do it in viewDidAppear: instead of viewDidLoad ... This solved the problem for me ...

+1
Jun 25 '14 at 6:15
source share

You probably set the UITextField to be too small in height. Try manually resizing it to two pixels. Or select it in the XIB editor and use the "Size for content placement" in the "Editor" menu. This should lead to the fact that the text field will be the right size so that this text change does not occur.

0
Aug 31 '13 at 0:10
source share

You must set the font property before the Text property.

0
Apr 30 '14 at 12:34
source share

Setting the Min Font Size property equal to the font size in Interface Builder worked for me

0
Mar 29 '17 at 22:24
source share



All Articles