フォントなしでテキスト自体をコピーして貼り付けるだけのこの行は機能します。
pasteBoard.string = MainController.customTextView.text
私は人々がこの質問について尋ねたのと同様の答えを見ようとしましたが、私が見るほとんどすべての答えはObjective Cであり、時代遅れです。以下のような他の回答を見て、この私が作業コピーを得たと思いますが、私はコピーしたテキストを貼り付けるとき、それは何も貼り付けられません。これが私のコピー機能のために持っているものです:
@objc func handleCopyButton() {
MainController.customTextView.resignFirstResponder() // dismiss keyboard
// Setup code in overridden UITextView.copy/paste
let selectedRange = MainController.customTextView.selectedRange
let selectedText = MainController.customTextView.attributedText.attributedSubstring(from: selectedRange)
// UTI List
let utf8StringType = "public.utf8-plain-text"
let rtfdStringType = "com.apple.flat-rtfd"
// Try custom copy
do {
// Convert attributedString to rtfd data
let fullRange = NSRange(location: 0, length: selectedText.string.count)
let data:NSData? = try selectedText.data(from: fullRange, documentAttributes: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.rtfd]) as NSData
if let data = data {
// Set pasteboard values (rtfd and plain text fallback)
pasteBoard.items = [[rtfdStringType: data], [utf8StringType: selectedText.string]]
}
} catch { print("Couldn't copy") }
// Copy if custom copy not available
MainController.customTextView.copy()
}
ご不明な点がございましたら、お気軽にお問い合わせください。前もって感謝します!
編集:私がやろうとしていたことでは、フォントをコピーして貼り付けることはできません(少なくともiOSでは、MacOSではできると思います)が、できることは、異なるように見えるユニコード文字をコピーして貼り付けることですフォント。それがあなたが興味を持っているものであるならば、この解決策をチェックしてください。
UIPasteboard.general.string = stringVar
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加