Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create UITextField with placeholder to the left and edited text to the right?

How to create UITextField with placeholder to the left and edited text to the right?

textfield image

UITextField itself does not allow using its properties to put placeholder and edited text to different sides. Try to set it in the storyboard -> attributes inspector -> alignment. They are both to the left or both the right. There is no special alignment only for placeholder or only for the text.

like image 499
zyxel Avatar asked Dec 14 '25 12:12

zyxel


2 Answers

To do this you should add a UILabel to the UITextField which is not editable and doesn't allow touches. Then set the text alignment on the UITextField to NSTextAlignmentRight.

like image 69
Woodstock Avatar answered Dec 17 '25 13:12

Woodstock


First, set the text alignment to the right:

    [textField setTextAlignment:NSTextAlignmentRight];

Fir the placeholder, you can add it as a subview, or use the leftView property:

    [textField setLeftView:<your label here>];
like image 22
Nikola Kirev Avatar answered Dec 17 '25 11:12

Nikola Kirev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!