问题描述
有没有办法在按钮被选中时更改按钮文本的颜色?
我尝试了类似的东西:
property myButton : missing value
myButton's setTintColor:(current application's NSColor's cyanColor)
但我收到以下错误:
-[NSButton setTintColor:]: 无法识别的选择器发送到实例 0x7fc865f2d000(错误 -10000)
解决方法
要将颜色等属性应用于按钮标题,您可以使用 NSAttributedString,例如:
set buttonTitle to myButton's title -- get current title
set attrString to current application's NSMutableAttributedString's alloc's initWithString:buttonTitle
attrString's addAttribute:(current application's NSForegroundColorAttributeName) value:(current application's NSColor's cyanColor) range:{0,buttonTitle's |length|}
set myButton's attributedTitle to attrString