6

As simple as it seems, I simply CANNOT find ANY way to do that (setFont: is not working) :

  • Have a NSTextView
  • Set its font to some NSFont.

Hint : (Pretty obvious, but whatever... ) IF the user adds any text, the new text is supposed to 'inherit' the exact same style...

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223

2 Answers2

7

I don't know what you're doing wrong, I am able to change the NSTextView's font in my own project. Are you sure you're setting the font AFTER the text view has been loaded? Check if the text view is loaded using NSLog.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
  • 3
    OMG! I've done the *very same* mistake, so many times... and I never remember what NOT to do next time. In a few words : NEVER play with an `NSTextView` in `awakeFromNib`... NEVER! Thanks a lot, mate! :-) – Dr.Kameleon Sep 10 '12 at 07:40
  • 1
    For those not using nibs - a similar solution helps me. I placed code to se the font in `viewWillAppear` instead of `viewDidLoad` – H K Feb 17 '15 at 00:24
6

You have to set font to textStorage, not to TextView

[[textView textStorage] setFont:[NSFont fontWithName:@"Menlo" size:12]];
Tutankhamen
  • 3,532
  • 1
  • 30
  • 38
  • That's *exactly* what I'm doing; however, it's still not working. Could it be that I'm populating the `NSTextView` via Bindings to an `NSArrayController` key? – Dr.Kameleon Sep 10 '12 at 01:01
  • It wil be good idea to show your code, becuase there are lot of things can be a reason of your issue... – Tutankhamen Sep 10 '12 at 01:05