Using swift, here is how I removed the images (added as NSTextAttachment) from the UITextView:
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if text.isEmpty {
textView.attributedText.enumerateAttribute(NSAttachmentAttributeName, inRange: NSMakeRange(0, textView.attributedText.length), options: NSAttributedStringEnumerationOptions(rawValue: 0)) { [weak self] (object, imageRange, stop) in
if NSEqualRanges(range, imageRange) {
self?.attributedText.replaceCharactersInRange(imageRange, withString: "")
}
}
}
return true
}
source
share