Re: Inserting a graphic
Re: Inserting a graphic
- Subject: Re: Inserting a graphic
- From: Eric Peyton <email@hidden>
- Date: Tue, 20 Nov 2001 08:04:27 -0600
It's much easier to add a text attachment than it would be to deal with
rtfd structures. See NSTextAttachment and NSAttributedString ...
Here is some sample code from Fire that does just this sort of thing
with an image (smiley) ...
static id happySmileyAttString = nil;
id happySmileyWrapper = [[NSFileWrapper alloc]
initWithPath:[[NSBundle mainBundle] pathForResource:HAPPY_SMILEY
ofType:IMAGE_TYPE]];
id happyAttachment = [[NSTextAttachment alloc]
initWithFileWrapper:happySmileyWrapper];
happySmileyAttString = [[NSAttributedString
attributedStringWithAttachment:happyAttachment] retain];
So now you have an attributed string with an image in an attachment.
now just add this attributed string to the TextView. The TextView's
TextStorage is just one big attributed string anyway.
Eric
On Monday, November 19, 2001, at 04:00 PM, David Remahl wrote:
I need to insert an NSImage into an NSTextView. I have checked out the
documentation, and the closest I can get is the replaceRange:withRTFD:.
So,
my question is, how can I generate an NSData object with the correct
RTFD
data for my NSImage? The 1994 openstep docu i found, said programmatic
RTFD
generation was not available. Has this changed? Should I instead use
some
other method? (maybe involving an NSPasteboard?).
/ Sincerely,
// David Remahl
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev