2015-12-16 5 views
6

मुझे UITextView में छवियों के पेस्टिंग का समर्थन करने की आवश्यकता है। क्लिपबोर्ड पर कॉपी की गई छवि के साथ, "Paste" विकल्प पॉप अप प्रतीत नहीं होता है। यह तब होता है जब क्लिपबोर्ड पर टेक्स्ट होता है।चिपकाए गए चित्र प्राप्त करने के लिए UITextView को कैसे सक्षम करें

यह कस्टम UITextView में paste विकल्प को ओवरराइड करने का तरीका है। लेकिन मैं कैसे विकल्प के साथ शुरू करने के लिए दिखाने के लिए पाने के लिए पर मदद की जरूरत है ...

// 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 get UIMenuController work for a custom view?, How to paste image from pasteboard on UITextView?

उत्तर

7

मैंने अपने स्वयं के प्रश्न का उत्तर दिया।

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{ 
    if (action == @selector(paste:) && [UIPasteboard generalPasteboard].image) 
     return YES; 
    else 
     return [super canPerformAction:action withSender:sender]; 
} 

आपका स्वागत है: आपको बस इतना करना है UITextView का कहना है इस UITextView विधि अधिभावी द्वारा "मैं चिपकाया छवियों प्राप्त कर सकते हैं" है।

+0

आपका कोड सही है, लेकिन एक छवि कॉपी करने के बाद मेरा पेस्ट विकल्प नहीं आ रहा है। इसे कैसे हल करें? –

+0

क्या आपको UITextView को इस कोड के साथ बनाए गए कस्टम क्लास का उदाहरण होने के लिए सेट करना याद आया? –

+0

@MattKoala धन्यवाद आपका उत्तर सही है। – Urmi

संबंधित मुद्दे