tags:

views:

248

answers:

2

How can I set the default font of an NSTextView component? I need to have an area in my app where users can make changes to a plain text file, and I'd like for the font to be a monospaced font.

+1  A: 
NSFont* font = <whatever>;
[textView setFont: font];
Dewayne Christensen
+1  A: 

Found it. The answer above was close, but wouldn't do it - had to access the textStorage object of the NSTextView first:

[[myNSTextView textStorage] setFont:[NSFont fontWithName:@"Menlo" size:11]];
joshbuhler
From the NSText (superclass of NSTextView) documentation: “Sets the font of all the receiver’s text to <var>aFont</var>.” If that didn't work for you, you should look into why.
Peter Hosey
Furthermore, you should use the user's preferred fixed-pitch font and size, not a hard-coded font and size. http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSFont_Class/Reference/Reference.html#//apple_ref/occ/clm/NSFont/userFixedPitchFontOfSize:
Peter Hosey