pistacchio
pistacchio

Reputation: 58863

NSTextView: apply paragraph style

I'm trying to apply the default paragraph style to a NSTextView but it doesn't seem to work. Any idea?

    var paragraphStyle:NSMutableParagraphStyle = NSMutableParagraphStyle();
    paragraphStyle.lineSpacing = 100.0;
    paragraphStyle.firstLineHeadIndent = 100.0;
    WLMainEditor.defaultParagraphStyle = paragraphStyle;

Upvotes: 1

Views: 973

Answers (1)

harrisg
harrisg

Reputation: 633

I find that it always works best to start with an existing paragraph style and make changes to it. If you don't have one to start with, use NSParagraphStyle.default()

let paragraphStyle = NSParagraphStyle.default().mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.lineSpacing = 100
paragraphStyle.firstLineHeadIndent = 100
WLMainEditor.defaultParagraphStyle = paragraphStyle

Also, at least in this code snippet, the paragraphStyle can (and should be) a let instead of a var since it's an Objective-C mutable object and not a Swift mutable collection.

Upvotes: 1

Related Questions