如何使用 AppleScript 更改按钮的颜色文本?

问题描述

有没有办法在按钮被选中时更改按钮文本的颜色?

我尝试了类似的东西:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...