Swift Mac OSX NSButton title color

PhiceDev picture PhiceDev · Jan 10, 2015 · Viewed 11.3k times · Source

I would like to know how to change title color to a NSButton in swift, I've seen lots of examples in objective-c but I think in swift the implementation is different, can anyone provide me an example?

Answer

bluedome picture bluedome · Jan 10, 2015

try this in viewDidLoad or somewhere.

In Swift 3:

    let pstyle = NSMutableParagraphStyle()
    pstyle.alignment = .center

    button.attributedTitle = NSAttributedString(string: "Title", attributes: [ NSForegroundColorAttributeName : NSColor.red, NSParagraphStyleAttributeName : pstyle ])