Reputation: 1066
I'm trying to set the position of my custom UITextField
icon. But when I change the imageView's frame's x and y values, it still places them top left.
Here's the viewWillAppear
method of my custom UITextField
class:
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 CGRectMake
call does nothing.
Any ideas? I've read that this may be caused by the element's AutoLayout feature. But if I remove that in the StoryBoard then XCode warns me about the app not looking great on multiple devices...
Upvotes: 3
Views: 4458
Reputation: 3733
Actually you are setting UIImageView
to leftView
of UITextField
. so it alway comes in left side. if you want UIImageView
to right side then there is rightView
option. if you want to add UIImageView to at your specific position then i suggest you to add as subview
rather then assigning its to leftView
or rightView
.
Hope this help you.
Upvotes: 2