Re: Inserting Graphics into NSTextView
Re: Inserting Graphics into NSTextView
- Subject: Re: Inserting Graphics into NSTextView
- From: Esteban Uribe <email@hidden>
- Date: Tue, 08 Apr 2003 16:47:44 -0700
Hi,
On Tuesday, April 08, 2003, at 10:01AM, <email@hidden> wrote:
>
How does one insert artwork (NSImage usually) into an NSTextView. I can find
>
documentation talking about inserting a Attachment (file wrapper) to an
>
Attribute String, and inserting that into a NSTextView, but not how to insert
>
an NSImage (the image is NOT associated with a file). Does one try to create
>
a Glyph (that does not seem suited for inserting graphics either)?
>
>
If someone has some source example, that would be great!
You'll neeed to create an NSTextAttachmentCell and NSTextAttachment.
Create the NSTextAttachmentCell with an image of your choice.
NSImage *image = [NSImage imageNamed:@"my cool artwork"];
NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell: image];
Then create the NSTextAttachment
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
[attachment setAttachmentCell: attachmentCell ];
Then create an NSAttributedString that contains the attachment glyph and the cell.
Just use the convenience constructor.
NSAttributedString *attributedString =
[NSAttributedString attributedStringWithAttachment: attachment];
Now insert this into the NSTextView's textContainer. release attachment, and attachmentCell
Hope this helps
Caveat Lector
I typed this really quick so there might be a few syntax errors.
-Esteban
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.