j3141592653589793238
j3141592653589793238

Reputation: 1904

How to center the text in a UITextField although there exists a leftView?

I'd like to center (horizontally align) the text in a text field (including the placeholder text) although there is a leftView added to the UITextField.

When adding a left view to a UITextField, the text is not centered anymore.

How can I fix this? I user should not be able to override the left view when entering text in the TextField.

This is an example:

enter image description here

I thought about adding the same view as the right view and set its alpha value to zero, but I don't think that would be an elegant approach.

Upvotes: 0

Views: 240

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100541

I would prefer to create it custom like this without leftView

UIView
       - 0 - UIImageView - 10 - UITexfield - 10
       - 0 -  separator (UIView) - height(1)- 0

Then copy paste that view for password

Upvotes: 1

Related Questions