Text in a UITextField will not be centered correctly

I think my question is thread related. I have a login screen with two UITextFields (user / pass). Both are horizontally centered with placeholder text. When I click on the field, the placeholder text jumps a little to the left, and the marker is positioned after the first character (which looks awful).

Text field in focus .

When I start typing, a clear button appears (as it should be), but the text is not correctly centered in the UITextField view.

Textfield with text

The problem only occurs when the text field has the first responder.

How can I make the darning text and placeholder text stay in the center of the text box ???

UPDATE: text field settings in the storyboard:

Text field settings in Storyboard

+6
source share
2 answers

I had the same problem, and I did what I created my own custom control with a UITextField above and a UILabel below both controls having the same width and height. When I need to display a text placeholder, I set the alpha label to 1, and when I need to hide the placeholder, I set alpha to 0. Also, I set the color inoput bg color to clear the color. In addition to all this, I implement UITextFieldDelegate (textFieldDidBeginEditing / textFieldDidEndEditing / shouldChangeCharactersInRange)

0
source

See control alignment in the image below and set accordingly. He will solve your problem enter image description here

-1
source

All Articles