NSButton how to color the text

后端 未结 12 1526
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 00:35

on OSX I have an NSButton with a pretty dark image and unfortunately it is not possible to change the color using the attributes inspector. See picture the big black button,

12条回答
  •  半阙折子戏
    2020-12-13 01:05

    This is how I get it done in Swift 4

     @IBOutlet weak var myButton: NSButton!
    
     // create the attributed string
     let myString = "My Button Title"
     let myAttribute = [ NSAttributedStringKey.foregroundColor: NSColor.blue ]
     let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
     // assign it to the button
     myButton.attributedTitle = myAttrString
    

提交回复
热议问题