简体   繁体   中英

Copy Custom font with with Font Style and Font Size

It's paste simple text when I copy text with below code.

let range = NSMakeRange(0, tvTexta.attributedText!.length)
            let rtfData = try! tvTexta.attributedText!.data(from: range,
                                                            documentAttributes: [ NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.rtf])

            UIPasteboard.general.items = [
                [ kUTTypePlainText as String : tvTexta.text! ],
                [ kUTTypeRTF as String : rtfData ]
            ]

I think the issue is how you are adding the data to the pasteboard. What you are doing is adding multiple items to the pasteboard, and what you actually want to do is add multiple representations of the same item :

UIPasteboard.general.items = [[
    kUTTypePlainText as String : tvTexta.text!,
    kUTTypeRTF as String : rtfData 
]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM