• 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 non RTF graphics into an NSTextView ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inserting non RTF graphics into an NSTextView ?


  • Subject: Re: inserting non RTF graphics into an NSTextView ?
  • From: Peter Ammon <email@hidden>
  • Date: Tue, 4 Dec 2001 02:56:09 -0500

On Monday, December 3, 2001, at 01:09 PM, Robert Miller wrote:

Hello,

Can someone tell me what the trick is to inserting a graphics object
into an NSTextView. Specifically I want to insert tiff images into an
NSTextView object at certain character locations. I 've poured over the
on-line documentation and was unable to find the clues that enable this
feature except for the reference to replaceCharactersInRange:withRTFD:
in the NSText class, rtf data which I do not have. I initialize an
NSImage using the class method imageNamed and then obtain its data using
TIFFRepresentation. I'de like to now insert that image into the
NSTextView. Are there any examples available on how to do this ?

If you're using imageNamed: to grab an image resource from your bundle, here's the quickest way to go about it:

NSString* pathToImage=[mainBundle pathForImageResource:@"myImageName"];
NSFileWrapper* wrapper=[[[NSFileWrapper alloc] initWithPath:pathToImage] autorelease];
NSTextAttachment* textAttachment=[[[NSTextAttachment alloc] initWithFileWrapper: wrapper] autorelease];
NSAttributedString* imageString=[NSAttributedString attributedStringWithAttachment:textAttachment];

now put that imageString into your text view (e.g. [[NSTextView textStorage] appendAttributedString:imageString] )

Hope this helps!

-Peter


References: 
 >inserting non RTF graphics into an NSTextView ? (From: Robert Miller <email@hidden>)

  • Prev by Date: alarm under Alert
  • Next by Date: Re: Question
  • Previous by thread: inserting non RTF graphics into an NSTextView ?
  • Next by thread: RE: inserting non RTF graphics into an NSTextView ?
  • Index(es):
    • Date
    • Thread