Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使用swift设置NSTextView的默认字体_Macos_Swift_Cocoa_Fonts_Nstextview - Fatal编程技术网

Macos 使用swift设置NSTextView的默认字体

Macos 使用swift设置NSTextView的默认字体,macos,swift,cocoa,fonts,nstextview,Macos,Swift,Cocoa,Fonts,Nstextview,加载一些文本后,我可以在NSTextView中更改字体 nameTextView.string=“一些文本” nameTextView.textStorage?.font=NSFont(名称:“Lucida Sans”,大小:15) 但是如何将此字体设置为默认字体 如果用户开始键入空的NsTextView控件,字体将始终返回控件默认字体,该字体似乎为“Helvetica常规”,大小为12 let font=NSFont(名称:“Lucida Sans”,大小:18) let attribu

加载一些文本后,我可以在NSTextView中更改字体

  • nameTextView.string=“一些文本”
  • nameTextView.textStorage?.font=NSFont(名称:“Lucida Sans”,大小:15)
但是如何将此字体设置为默认字体


如果用户开始键入空的NsTextView控件,字体将始终返回控件默认字体,该字体似乎为“Helvetica常规”,大小为12

let font=NSFont(名称:“Lucida Sans”,大小:18)
let attributes=NSDictionary(对象:font!,forKey:NSFontAttributeName)

nameTextView.typingAttributes=attributes
以下内容适合我

func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Insert code here to initialize your application
    nameTextView.font = NSFont(name: "Lucida Sans", size: 15)

字体是可选的,因为系统上可能不存在特定的字体。最好使用
如果let font=NSFont(名称:“Lucida Sans”,大小:18){let attributes=NSDictionary(object:font,forKey:NSFontAttributeName)\n nameTextView.typingAttributes=attributes}
我今天通过艰苦的学习学会了这一点,因为我的开发机器有Consolas字体,但这不是Mac上的默认字体。