Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set font in NSTextView?

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...

like image 274
Dr.Kameleon Avatar asked Sep 10 '12 00:09

Dr.Kameleon


2 Answers

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.

like image 140
TheAmateurProgrammer Avatar answered Sep 30 '22 18:09

TheAmateurProgrammer


You have to set font to textStorage, not to TextView

[[textView textStorage] setFont:[NSFont fontWithName:@"Menlo" size:12]];
like image 32
Tutankhamen Avatar answered Sep 30 '22 18:09

Tutankhamen