How to paste image from pasteboard on UITextView?

前端 未结 3 1735
心在旅途
心在旅途 2020-12-10 19:49

I have the following code on a keyboard extensión

let pasteboard = UIPasteboard.generalPasteboard()
var image = UIImage(named: \"myimage\");
pasteboard.image         


        
3条回答
  •  猫巷女王i
    2020-12-10 20:26

    UITextView only supports pasting text out of the box. You can subclass it and add support for pasting images, which can be implemented using attributed string text attachments.

    NSHipster's writeup on UIMenuController and this Stack Overflow question explain the paste logic.

提交回复
热议问题