Re: Insert Picture in TextView
Re: Insert Picture in TextView
- Subject: Re: Insert Picture in TextView
- From: Scott Anguish <email@hidden>
- Date: Sun, 2 Jun 2002 14:24:59 -0400
On Sunday, June 2, 2002, at 09:12 AM, Albert Atkinson wrote:
Hello!
I have looked all over the cocoa documentation and can not find what I
am looking for. I would like to hook up a button so that when the user
clicks it then the action will place a picture in a text view called
"icon2" (which is in the project).
\
You want to create an NSMutableAttributedString with an attachment
for the icon.
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.