如何改变 NSColorWell 的动作? [英] How to change the action of NSColorWell?

查看:32
本文介绍了如何改变 NSColorWell 的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 NSColorWell 作为按钮来更改所选文本的颜色.由于 NSColorWell 是 NSControl 的对象,因此它具有目标和操作.我想,该操作是执行代码以更改 NSTextView 中所选文本的颜色.我在哪里可以找到 NSColorWell 动作的代码?我想改变它,我可以使用 NSColorWell 来更改所选文本的背景,并最终在 ToolBar 中有两个 NSColorWell 按钮:一个用于更改文本的前景色,第二个用于文本的背景色.

I can use NSColorWell as button to change the color of selected text. Since NSColorWell is object of an NSControl it has target and action. I guess, the action is implementing the code to change the color of the selected text in NSTextView. Where can I find this code for NSColorWell action? I would like to change it in away that I can use NSColorWell to change the background of the selected text, and ultimately to have in ToolBar two NSColorWell buttons: one to change text's foreground color and second one for text's background color.

推荐答案

NSColorWell 只是一个改变颜色的矩形控件.

NSColorWell is just a rectangular control to change a color.

  • 您可以创建一个 IBAction 并将其连接到 Interface Builder 的 Connections Inspector (⌥⌘6) 中的颜色井的动作

  • You can either create an IBAction and connect it to the action of the color well in the Connections Inspector (⌥⌘6) of Interface Builder

@IBAction func changeColor(_ sender : NSColorWell)
{
   let color = sender.color
   // do something with the color
}

  • 或者将 Interface Builder 的 Bindings Inspector (⌥⌘7) 中的 value 绑定到一个 dynamic 属性,这个例子将将颜色井设置为默认值绿色.

  • Or bind the value in Bindings Inspector (⌥⌘7) of Interface Builder to a dynamic property, this example will set the color well to a default value of green.

    dynamic var color : NSColor = .green {
       didSet {
         // do something with the color
       }
    }
    

  • 这篇关于如何改变 NSColorWell 的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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