1

I have problems changing the color of the title of a NSButton. I tried this:

button.setTitleColor(NSColor.blackColor())

or this

button.titleColor = NSColor.blackColor()

and this

button.title.textColor = NSColor.blackColor()

but none of these three methods seems to be available! How could that be possible, the compiler says that these method are not present.

AppKit and Cocoa are imported. What is the solution?

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Matt
  • 773
  • 2
  • 15
  • 32

1 Answers1

1

EDIT

Just realized that the question was for OS X. Anyway, this is how you would do it:

let style = NSMutableParagraphStyle()
    style.alignment = .CenterTextAlignment

button.attributedTitle = NSAttributedString(string: "foo", attributes: [ NSForegroundColorAttributeName : NSColor.blackColor(), NSParagraphStyleAttributeName : style ])
Dhruv Ramani
  • 2,633
  • 2
  • 22
  • 29