I have the following code on a keyboard extensión
let pasteboard = UIPasteboard.generalPasteboard()
var image = UIImage(named: \"myimage\");
pasteboard.image
Create an NSTextAttachment from the image and an attributed string with the TextAttachment. Then set the attributedText property of the UITextView. Subclass UITextView and override the paste(_:) method:
override func paste(_ sender: Any?) {
let textAttachment = NSTextAttachment()
textAttachment.image = UIPasteboard.general.image
attributedText = NSAttributedString(attachment: textAttachment)
}