Je možné vložiť obrázok (nie obrázok na pozadí) do NSTextView
? Niečo ako:
Ahoj ako sa máš?
a mal by zobrazovať obrázok „smajlík“. Mám NSTextView
a an NSImage
.
odpovede:
33 pre odpoveď č. 1Vložte NSImage do NSTexView:
NSImage * pic = [[NSImage alloc] initWithContentsOfFile:@"/Users/Anne/Desktop/Sample.png"];
NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
[attachment setAttachmentCell: attachmentCell ];
NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment: attachment];
[[textView textStorage] appendAttributedString:attributedString];
V hlavičkovom súbore:
IBOutlet id textView;