Swift Mac OSX NSButton标题颜色 [英] Swift Mac OSX NSButton title color

查看:342
本文介绍了Swift Mac OSX NSButton标题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何迅速将标题颜色更改为NSButton,我在Objective-c中看到了很多示例,但是我认为在实现上有所不同,有人可以给我提供示例吗?

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 anyone provide me an example?

推荐答案

viewDidLoad或其他地方尝试此操作.

try this in viewDidLoad or somewhere.

在Swift 3中:

    let pstyle = NSMutableParagraphStyle()
    pstyle.alignment = .center

    button.attributedTitle = NSAttributedString(string: "Title", attributes: [ NSForegroundColorAttributeName : NSColor.red, NSParagraphStyleAttributeName : pstyle ])

这篇关于Swift Mac OSX NSButton标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆