I have got a text field:
let usn_text_field: UITextField = {
let tf = UITextField()
tf.placeholder = "Username"
tf.translatesAutoresizingMaskIntoConstraints = false
tf.background = #imageLiteral(resourceName: "usericon2")
return tf
}()
This textfield shows an input field with an image expanded. But I want a simple icon on the left of the input, how can i resize and reposition the image?
Use the leftView
attribute of the text field and put a UIImageView
there to place an image to the left side of your text field.
tf.leftView = UIImageView(image: #imageLiteral(resourceName: "usericon2"))
If you want to show it always, change the leftViewMode property of the text field:
tf.leftViewMode = .always
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With