0

Currently working in Swift with Xcode but I want to add, for example, an image icon into my placeholder position for a text field. Many modern UI designs feature this on their log in/log out pages. How would I be able to implement something like this?

NewBeginnings
  • 347
  • 4
  • 22

2 Answers2

0

You can add a UIButton using Interface Builder and have both an image and text into one object.

Simply drag and drop a UIButton from the object library panel to a UIViewController. Check the Attributes Inspector and set the Image property to an image you've added to the project either using the Assets Catalog or from an image you've added to the project library. Then set the Title property to the text you wish to display. You can then select Image in the Edge dropdown property and adjust the position of the image relative to the text.

ninjaneer
  • 6,951
  • 8
  • 60
  • 104
  • I'm sorry. I misread. You're looking to put a UIImage in a UITextField. You can check this SO answer. http://stackoverflow.com/a/13509230/505259 . Instead of using `rightView`, you want to set the `leftView` property. – ninjaneer Aug 30 '15 at 22:49
0

you can check this code for your text field image icon

 @IBOutlet weak var name: UITextField!
override func viewDidLoad() {
    super.viewDidLoad()
    name.leftViewMode = .always
    let nameimage = UIImageView()
    nameimage.frame = CGRect(x: 0, y: 0, width: 25, height: 25)
    let anam = #imageLiteral(resourceName: "m")
    nameimage.image = anam
    name.leftView = nameimage
}