• 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: [newbie] Font attributes in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] Font attributes in NSTextView


  • Subject: Re: [newbie] Font attributes in NSTextView
  • From: Matt Neuburg <email@hidden>
  • Date: Mon, 9 Sep 2002 21:31:58 -0700

On Tue, 10 Sep 2002 00:32:26 +0200, Jens Baumeister
<email@hidden> said:

>I have an NSTextView that'M addming lines to. I want some of these
>lines to be bold (and perhaps in italics) and others to be plain text.
>I've found out how to use NSAttributedString, but I cannot add an
>attributed string to a text view.
>
>How would I do this?

An NSTextView has an NSTextStorage, and an NSTextStorage *is* an
NSAttributedString. Example:

[textview setString: @"Hello, world!"];
[[textview textStorage]
applyFontTraits: NSBoldFontMask range: NSMakeRange(7,5)];

On the other hand note that if *all* you want to do is change font traits,
that's a font matter, not an attributed-string matter, so you can do that
directly, because an NSTextView is an NSText:

[textview setString: @"Hello, world!"];
[textview setFont:
[[NSFontManager sharedFontManager] convertFont: [textview font]
toHaveTrait: NSBoldFontMask]
range: NSMakeRange(7,5)];

Take your pick. m.
--

matt neuburg, phd = email@hidden, http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
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.

  • Follow-Ups:
    • Re: [newbie] Font attributes in NSTextView
      • From: Scott Anguish <email@hidden>
  • Prev by Date: [Q] Animating (split) views
  • Next by Date: Re: Build Errors
  • Previous by thread: Re: [newbie] Font attributes in NSTextView
  • Next by thread: Re: [newbie] Font attributes in NSTextView
  • Index(es):
    • Date
    • Thread