On 13/05/2009, at 12:18 AM, sandeep chaudhary wrote:

I am using the NSTextView class. i have created the NSTextView control and create a outlet for this. Now i am adding some text on this control programatically. Text is shown on this field at run time. Now i want some word in string to be shown on bold face and some in normal font.(for example if i have set "humpty dumpty" to my NSTextView , then i want "Humpty" to be shown in bold face and "dumpty" to be in normal face. I have serach how to set the bold face for some word in NSTextView, but could not find any solution.
Please describe me how to do this.
any help is much appriciated


NSTextView has a -textStorage method that returns a NSTextStorage instance, which is a subclass of NSMutableAttributedString. The docs for that class contain the answer to your question. Briefly, you need to figure out the ranges of the characters that you want to apply the font attributes to, then use the [textStorage addAttribute:NSFontAttributeName value:theBoldFont range:theCharacterRange] method to do it, or -applyFontTraits:range:, depending on what you're doing.

Generally it's much easier to drive this using the Font Panel, which NSTextView is already set up to handle. Just ensure that - setUsesFontPanel: is called with YES.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to