blu*_*ome 22
试试这个viewDidLoad
或某个地方.
在Swift 3中:
let pstyle = NSMutableParagraphStyle()
pstyle.alignment = .center
button.attributedTitle = NSAttributedString(string: "Title", attributes: [ NSForegroundColorAttributeName : NSColor.red, NSParagraphStyleAttributeName : pstyle ])
Run Code Online (Sandbox Code Playgroud)
斯威夫特4
我已添加此作为附加答案,因为它仅更改请求的属性而不覆盖或添加其他属性.
if let mutableAttributedTitle = button.attributedTitle.mutableCopy() as? NSMutableAttributedString {
mutableAttributedTitle.addAttribute(.foregroundColor, value: NSColor.white, range: NSRange(location: 0, length: mutableAttributedTitle.length))
button.attributedTitle = mutableAttributedTitle
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9504 次 |
最近记录: |