Skip navigation.
 
mlRe: Need help setting font of NSTextView
FROM : Douglas Davidson
DATE : Thu Jan 10 19:27:32 2002

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


Related mailsAuthorDate
mlNeed help setting font of NSTextView Doug Brown Jan 10, 07:19
mlRe: Need help setting font of NSTextView Douglas Davidson Jan 10, 19:27
mlRe: Need help setting font of NSTextView Doug Brown Jan 11, 01:14
mlRe: Need help setting font of NSTextView Douglas Davidson Jan 11, 04:10
mlRe: Need help setting font of NSTextView Doug Brown Jan 11, 05:52
mlRe: Need help setting font of NSTextView Douglas Davidson Jan 11, 18:45