I'm trying to add an image as NSTextAttachment
to UITextField
, but all I get is ,
Code within custom UITextField
:
let myAttachment = NSTextAttachment()
myAttachment.image = myImage
myAttachment.bounds = CGRect(origin: .zero, size: myImage.size)
let myImageString = NSAttributedString(attachment: myAttachment)
let updatedText = NSMutableAttributedString()
updatedText.append(myImageString)
let myTextString = NSAttributedString(string: ", " + (self.text ?? ""))
updatedText.append(myTextString)
self.attributedText = updatedText