• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to set font in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to set font in NSTextView


  • Subject: Re: how to set font in NSTextView
  • From: Graham Cox <email@hidden>
  • Date: Wed, 13 May 2009 00:30:25 +1000


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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >how to set font in NSTextView (From: sandeep chaudhary <email@hidden>)

  • Prev by Date: Re: Resolution Independent View?
  • Next by Date: Re: NSTimer with userInfo
  • Previous by thread: Re: how to set font in NSTextView
  • Next by thread: NSTimer with userInfo
  • Index(es):
    • Date
    • Thread