简体   繁体   English

如何在NSTextView中设置字体?

[英]How to set font in NSTextView?

As simple as it seems, I simply CANNOT find ANY way to do that ( setFont: is not working) : 看起来很简单,我根本无法找到任何方法( setFont:不工作):

  • Have a NSTextView 有一个NSTextView
  • Set its font to some NSFont . 将其字体设置为某些NSFont

Hint : (Pretty obvious, but whatever... ) IF the user adds any text, the new text is supposed to 'inherit' the exact same style... 提示:(很明显,但无论如何......)如果用户添加任何文本,新文本应该“继承”完全相同的样式......

I don't know what you're doing wrong, I am able to change the NSTextView's font in my own project. 我不知道你做错了什么,我能够在我自己的项目中更改NSTextView的字体。 Are you sure you're setting the font AFTER the text view has been loaded? 您确定在文本视图加载后设置了字体吗? Check if the text view is loaded using NSLog. 检查是否使用NSLog加载了文本视图。

您必须将字体设置为textStorage,而不是TextView

[[textView textStorage] setFont:[NSFont fontWithName:@"Menlo" size:12]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM