首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用AppleScript更改按钮的文本颜色?

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

Stack Overflow用户
提问于 2021-04-22 01:53:15
回答 1查看 56关注 1票数 0

当按钮被选中时,有没有办法改变它的文本颜色?

我试过这样的方法:

代码语言:javascript
复制
property myButton : missing value

myButton's setTintColor:(current application's NSColor's cyanColor)

但我得到的错误如下:

-NSButton setTintColor::无法识别的选择器发送到实例0x7fc865f2d000 (错误-10000)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-23 06:18:36

要将颜色等属性应用于按钮标题,可以使用NSAttributedString,例如:

代码语言:javascript
复制
    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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67201107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档