You can add images to text using NSAttributedString
and NSTextAttachment
.
I haven't used them in a while but I believe you can do something like this...
let magnifyingGlassAttachment = NSTextAttachment(data: nil, ofType: nil)
magnifyingGlassAttachment.image = UIImage(named: "MagnifyingGlass")
let magnifyingGlassString = NSAttributedString(attachment: magnifyingGlassAttachment)
now you can use the magnifyingGlassString
attributed string and add it as part of the attributed text to the UITextField
.
I believe you can also specify exactly how the magnifying glass renders alongside the string (how it wraps etc...)
Something like this...
var attributedText = NSMutableAttributedString(attributedString: magnifyingGlassString)
let searchString = NSAttributedString(string: "Search for stuff")
attributedText.appendAttributedString(searchString)
textField.attributedPlaceholder = attributedText