Re: inserting graphics into NSString output
Re: inserting graphics into NSString output
- Subject: Re: inserting graphics into NSString output
- From: Scott Anguish <email@hidden>
- Date: Mon, 13 May 2002 06:06:29 -0400
On Saturday, May 11, 2002, at 10:51 PM, Nathan Lee wrote:
Hello, I'm a newbie, and I'm trying to learn the NSString system. Could
someone help me out with inserting an image into a string?
You can't insert an image into an NSString.. only
NSAttributedString can hold an NSTextAttachment
You can make a new NSAttributedString with an attachment by calling
+attributedStringWithAttachment: and passing the NSTextAttachment as the
argument.
Then, you can append the NSAttributedString onto the textBox's
textStorage using
[[textBox textStorage] appendAttrbutedString:myStringWithTheAttachment]
- (IBAction)appendAnImage:sender;
{
NSTextAttachment *theAttachment;
NSFileWrapper *theWrapper = [[[NSFileWrapper alloc]
initWithPath:[[NSBundle mainBundle] pathForResource:@"image"
ofType:@"tiff"]] autorelease];
theAttachment = [[[NSTextAttachment alloc]
initWithFileWrapper:theWrapper] autorelease];
[[theTextView textStorage]
appendAttributedString:[NSAttributedString
attributedStringWithAttachment:theAttachment]];
}
_______________________________________________
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.