6
UITextView
に画像を貼り付けることをサポートする必要があります。クリップボードにコピーされた画像では、 "Paste
"オプションは表示されません。クリップボードにテキストがあるときに機能します。UITextViewで貼り付けられた画像を受信する方法
カスタムUITextView
のpaste
オプションを上書きする方法です。 How to get UIMenuController work for a custom view?、:しかし、私はそれに関連するいくつかの質問に出くわしたが、彼らは私のような経験の浅い開発者にとって有用ではなかったで開始するまで表示するオプションを取得する方法についてのヘルプ...
// This gets called when user presses menu "Paste" option
- (void)paste:(id)sender{
UIImage *image = [UIPasteboard generalPasteboard].image;
if (image) {
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = image;
NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:textAttachment];
self.attributedText = imageString;
} else {
// Call the normal paste action
[super paste:sender];
}
}
が必要How to paste image from pasteboard on UITextView?
コードは正しいですが、画像をコピーした後に貼り付けオプションが表示されません。これを解決するには? –
UITextViewをこのコードで作成したカスタムクラスのインスタンスに設定することを忘れましたか? –
@MattKoalaあなたの答えは完璧です。 – Urmi