UITextField Icon Quick Position

I am trying to set the position of my custom icon UITextField

. But when I change the x and y values โ€‹โ€‹of the imageView, it still puts them in the top left corner.

Here's the method of viewWillAppear

my custom class UITextField

:

var imageView = UIImageView();
var image = UIImage(named: "user-icon.png");
imageView.image = image;
imageView.frame = CGRectMake(100, 0, 20, 19);
usernameTextField.leftView = imageView;
usernameTextField.leftViewMode = UITextFieldViewMode.Always

      

Changing the x and y parameters in the call CGRectMake

does nothing.

Any ideas? I read that this can be caused by an AutoLayout element. But if I remove that in StoryBoard then Xcode warns me that the app doesn't look great on multiple devices ...

+3


source to share


1 answer


In fact you are installing UIImageView

on leftView

in UITextField

. therefore it always comes to the left. if you want UIImageView

to the right then there is an option rightView

. if you want to add the UIImageView at your specific position then I suggest you add as subview

and then assigning it leftView

or rightView

.



Hope it helps you.

+2


source







All Articles