[英]How to set the default font for a NSTextView?
I'm using a textView with "Rich Text" option disabled to display some plain text. 我正在使用禁用“富文本”选项的textView来显示一些纯文本。 I can't find a way to set the default font. 我找不到设置默认字体的方法。 If I put in some text in IB (which I don't want anyway) I can then set the font in IB interface, but when users delete the font and start to type, the text changes to a different font and size. 如果我在IB中放入一些文本(我不想要),我可以在IB界面中设置字体,但是当用户删除字体并开始输入时,文本会更改为不同的字体和大小。 I read some questions and answers here and developer documentation without find a solution. 我在这里阅读了一些问题和答案以及开发人员文档而没有找到解决方
If you know the exact name of the font you want to use, like for this case "AvenirNextCondensed" 如果你知道你想要使用的字体的确切名称,就像这个案例“AvenirNextCondensed”
let tv = NSTextView()
tv.font = NSFont(name: "AvenirNextCondensed-Regular", size: 15.0)!
If you want to use the system font of size whatever, do it like this (where size
is a CGFloat
) 如果你想使用任何大小的系统字体,那就这样做( size
是CGFloat
)
tv.font = NSFont.systemFont(ofSize: size)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.