• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Inserting Graphics into NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Re: Inserting Graphics into NSTextView
  • Next by Date: Re: How-To: private framework
  • Previous by thread: Re: Inserting Graphics into NSTextView
  • Next by thread: NSTableView and crashes, what am I doing wrong?
  • Index(es):
    • Date
    • Thread