Re: how to insert a NSAttributedString into a NSTextview ?
Re: how to insert a NSAttributedString into a NSTextview ?
- Subject: Re: how to insert a NSAttributedString into a NSTextview ?
- From: Jonathan Jackel <email@hidden>
- Date: Sun, 26 Dec 2004 13:32:37 -0500
I recommend that you read up on the text system architecture, but this should help for now.
A text view is the view element of a group of objects that manage text. Each text view has a text storage object of the NSTextStorage class. That class is a subclass of NSMutableAttributedString, which is in turn a subclass of NSAttributedString.
That means you can tell the text view's text storage to do the same kinds of things as an NSMutableAttributedString, such as replacing its attributed string or inserting an attributed string at a particular place.
If you want to completely replace the contents of a text view with an attributed string, you can do this:
[[myTextView textStorage] setAttributedString:myAttributedString];
If you want to insert an attributed string at a particular location, you can do this:
[[myTextView textStorage] insertAttributedString:myAttributedString atIndex:location];
Jonathan
On Dec 25, 2004, at 3:22 PM, Jérémie Banier wrote:
Hello,
I'm pretty new to cocoa and I would like to know how you can insert an Attributed string into a NSTextView ...
I was expecting the following to do some things but I does not do much ...
NSMutableString* s = [ NSMutableString stringWithFormat: @"0xlx:", fh?foff:(unsigned long)p ];
foff += sizeof(ppc_word);
tempString = [tempString initWithString: s ];
[ tempString addAttribute: NSForegroundColorAttributeName
value: [NSColor blueColor]
range: NSMakeRange(0, [ s length ])];
[ myRTFTxt replaceCharactersInRange: NSMakeRange(0, [ [ myRTFTxt string ] length ])
withString: tempString ];
I would appreciate any comments, pointer, samples ...
Many thanks,
Jéré.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden