Swift Mac OSX NSButton title color

后端 未结 3 473
清歌不尽
清歌不尽 2021-01-18 04:54

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 a

3条回答
  •  佛祖请我去吃肉
    2021-01-18 05:12

    Swift 4

    I've added this as an additional answer since it changes only the requested attribute without overwriting or adding additional ones.

    if let mutableAttributedTitle = button.attributedTitle.mutableCopy() as? NSMutableAttributedString {
        mutableAttributedTitle.addAttribute(.foregroundColor, value: NSColor.white, range: NSRange(location: 0, length: mutableAttributedTitle.length))
        button.attributedTitle = mutableAttributedTitle
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题