I have this code for creating an Attributed String with an image on a UITextView
func setImageOnString(imageName: String) {
let fullString = NSMutableAttributedString(attributedString: attributedText) let imageAttachment = NSTextAttachment() imageAttachment.image = #imageLiteral(resourceName: "UncheckedImage") imageAttachment.bounds = CGRect(x: 0, y: 0, width: 14, height: 14) let image1String = NSAttributedString(attachment: imageAttachment) let myCustomAttribute = [ "MyCustomAttributeName": "some value"] fullString.append(image1String) fullString.addAttributes(myCustomAttribute, range: selectedRange) self.attributedText = fullString }
But then I can't find a way of changing this image when something happen like a touch. The problem isn't the touch, it is changing the image.