Copy NSAttributedString in UIPasteBoard

前端 未结 4 1371
故里飘歌
故里飘歌 2020-11-30 09:15

How do you copy an NSAttributedString in the pasteboard, to allow the user to paste, or to paste programmatically (with - (void)paste:(id)sender

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 09:56

    The pasteboard manager in OSX can auto convert between a lot of textual and image types.

    For rich text types, you'd usually place RTF into the pasteboard. You can create RTF representation from an attributed string, and vice versa. See the "NSAttributedString Application Kit Additions Reference".

    If you have images included as well, then use the RTFd instead of RTF flavor.

    I don't know the MIME types for these (I'm used to the Carbon Pasteboard API, not the Cocoa one), but you can convert between UTIs, Pboard and MIME Types using the UTType API.

    UTI for RTF is "public.rtf", for RTFd it's "com.apple.flat-rtfd".

提交回复
热议问题