Skip to content

Instantly share code, notes, and snippets.

@zhaorui
Created February 8, 2017 15:59
NSButton extension to set title color
extension NSButton {
var titleTextColor : NSColor {
get {
let attrTitle = self.attributedTitle
return attrTitle.attribute(NSForegroundColorAttributeName, at: 0, effectiveRange: nil) as! NSColor
}
set(newColor) {
let attrTitle = NSMutableAttributedString(attributedString: self.attributedTitle)
let titleRange = NSMakeRange(0, self.title.characters.count)
attrTitle.addAttributes([NSForegroundColorAttributeName: newColor], range: titleRange)
self.attributedTitle = attrTitle
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment