Re: Need help setting font of NSTextView
Re: Need help setting font of NSTextView
- Subject: Re: Need help setting font of NSTextView
- From: Doug Brown <email@hidden>
- Date: Thu, 10 Jan 2002 16:14:28 -0800
Hi Douglas,
I tried overriding rangeForUserCharacterAttributeChange to:
return NSMakeRange(0, [[self string] length]);
And it only seems to change the font attributes when there is nothing
inside the textView. Any ideas?
Thanks,
Doug
On Thursday, January 10, 2002, at 10:27 AM, Douglas Davidson wrote:
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