Swift Mac OSX NSButton title color

后端 未结 3 496
清歌不尽
清歌不尽 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:22

    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 ])
    

提交回复
热议问题