Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set default Font for NSTextView with swift

I am able to change the Font in NSTextView AFTER I have loaded some text.

  • nameTextView.string = "Some Text"
  • nameTextView.textStorage?.font = NSFont(name: "Lucida Sans", size: 15)

but how can I set this Font as the default Font?

if the user starts typing in an empty NsTextView control, the Font always returns to the controls default Font which seems to be 'Helvetica Regular', size 12

like image 250
Hanspeter Stocker Avatar asked Mar 23 '15 22:03

Hanspeter Stocker


2 Answers

Ok, after a lot of try and error I found a solution:

let font = NSFont(name: "Lucida Sans", size: 18)
let attributes = NSDictionary(object: font!, forKey: NSFontAttributeName)
        
nameTextView.typingAttributes = attributes

I put that code lines in function awakefromNib

like image 77
Hanspeter Stocker Avatar answered Nov 04 '22 02:11

Hanspeter Stocker


The following works for me

func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Insert code here to initialize your application
    nameTextView.font = NSFont(name: "Lucida Sans", size: 15)
like image 10
Erich Kuester Avatar answered Nov 04 '22 01:11

Erich Kuester