Re: inserting non RTF graphics into an NSTextView ?
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