Hanspeter Stocker
Hanspeter Stocker

Reputation: 393

set default Font for NSTextView with swift

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

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

Upvotes: 7

Views: 5424

Answers (2)

Erich Kuester
Erich Kuester

Reputation: 101

The following works for me

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

Upvotes: 10

Hanspeter Stocker
Hanspeter Stocker

Reputation: 393

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

Upvotes: 15

Related Questions