简体   繁体   English

如何设置NSTextView的默认字体?

[英]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 ) 如果你想使用任何大小的系统字体,那就这样做( sizeCGFloat

tv.font = NSFont.systemFont(ofSize: size)

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

相关问题 使用swift为NSTextView设置默认字体 - set default Font for NSTextView with swift 如何设置NSTextView的默认书写方向? - How to set the default writing direction for NSTextView? 如何在NSTextView中获取某些字体文本的字符串? - How to get a string of certain font text in a NSTextView? 如何在Swift中为NSTextView设置第一响应者? - How to set first responder for NSTextView in Swift? 如何阻止NSTextView显示指定字体不支持的字符 - How to stop NSTextView from displaying characters that are not supported in a specified font 如何在NSTextView中的一行换行文本中获取等宽字体的字符数? - How to get the number of characters of monospaced font in a line of wrapped text in NSTextView? 如何使用显式 NSLayoutManager、NSTextStorage、NSTextContainer 以编程方式设置 NSTextView? - How to set up an NSTextView programmatically with explicit NSLayoutManager, NSTextStorage, NSTextContainer? 如何更改NSMutableAttributedString的默认字体和字体大小 - how to change the default font and font size of NSMutableAttributedString 如何获取UITabBarItem的默认字体? - How to get default font of UITabBarItem? 如何在 Swift 中设置自定义字体的字体粗细 - How to set font weight of a custom font in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM