informatiker informatiker - 4 months ago 105
iOS Question

Swift add icon/image in UITextField

I would like to add icon/image in UITextField. The icon/image should be left to placeholder.

enter image description here

I tried this:

var imageView = UIImageView();
var image = UIImage(named: "email.png");
imageView.image = image;
emailField.leftView = imageView;


Thanks.

Answer

Try adding emailField.leftViewMode = UITextFieldViewMode.Always

(Default leftViewMode is Never)