Image in Text View

Hi!
I have question. How can I insert image to text view with smaller size(scaled to text view), but with keeping quality? Like in Notes on iOS - picture with high quality weight around 800kB. Thanks.

Replies

You can use NSTextAttachment to insert an image in a UITextView's textStorage.

let attachment = NSTextAttachment()
attachment.image = scaledImage
let imageString = NSAttributedString(attachment: attachment)
textView.textStorage.insert(imageString, at: indexWhereYouWantTheImage)
Post not yet marked as solved Up vote reply of nima Down vote reply of nima