Re: Need help setting font of NSTextView
Re: Need help setting font of NSTextView
- Subject: Re: Need help setting font of NSTextView
- From: Douglas Davidson <email@hidden>
- Date: Thu, 10 Jan 2002 10:27:32 -0800
On Wednesday, January 9, 2002, at 10:19 PM, Doug Brown wrote:
I'm having trouble figuring out how to what seems like a simple task in
Cocoa. I have an NSTextView that is not editable, and I want to be able
to use NSFontPanel (or just a menu with the font names in it or
something) to set the font (and size) of the entire text within it.
I've been trying to read the documentation, but it's confusing me. Does
NSFontPanel only work when you're using an editable text view? If
possible, I'd also like to simultaneously set the font of an
NSTextField when that happens. Could anyone guide me in the right
direction? Thanks!
When a textview isn't editable, the user can't change it. The method
that is called when changes occur in the font panel is changeFont:, and
this and a number of other methods apply their changes to the range
returned from rangeForUserCharacterAttributeChange. If a textview is
not editable, rangeForUserCharacterAttributeChange returns {NSNotFound,
0}, which prevents these sorts of changes from taking effect. If the
textview is editable, then changeFont: calls the font manager method
convertFont: on each font present in the text, to apply the changes made
in the font panel to the text.
You should be able to do what you want by subclassing and overriding
changeFont:, rangeForUserCharacterAttributeChange, or both.
Douglas Davidson