First of all, you should definitely not add an image as a subroutine to a shortcut. This is enough to set the leftView property.
textField.addSubview(leftImageView) // Delete this line
Secondly, any x or y offsets that you apply to the left frame of view are ignored. The text box will only care about the size of the view. If you want to add registration around the image, one option is to use the container view and place the image inside.
let leftImageView = UIImageView() leftImageView.image = leftImage let leftView = UIView() leftView.addSubview(leftImageView) leftView.frame = CGRectMake(0, 0, 30, 20) leftImageView.frame = CGRectMake(0, 0, 15, 20) textField.leftView = leftView
Another option would be to subclass UITextField and override leftViewRectForBounds .
source share