Mac OS AppKit文档翻译——NSButton

免费翻译技术文档的空闲,我用一年时间,翻译的美国大作家作品《明日此时》,欢迎大家品鉴吐槽哦,亚马逊有电子版购买阅读哦~

NSButton

NSButton is a subclass of the NSControl class. An NSButton object sends an action message to a target object, such as a view controller, when the button is clicked. When configured as continuous, the button continues to send repeating action messages at timed intervals until released.

NSButton类是NSControl的子类。当一个按钮被点击后,NSButton对象会发送一条动作消息给目标对象,比如给视图控制器。当动作是连续的时候,这个按钮也会不间断的重复发送动作消息,直到按钮被释放。


Overview

There are multiple types of buttons, each with a different user interface and behavior. Button types are defined in the NSButtonCell class, and are configured by calling the setButtonType(_:) method.

有多种不同类型的按钮,每一种按钮都有不同的界面和特征。按钮的类型被定义在NSButtonCell类里,通过调用setButtonType(_:)方法来设置按钮的类型。

If you configure it as an accelerator button (type NSAcceleratorButton or NSMultiLevelAcceleratorButton), a button can be set to send action messages when changes in pressure occur when the user clicks on the button.

如果选用的是一个加速按钮(如NSAcceleratorButton类或NSMultiLevelAcceleratorButton类),当用户点击按钮的动作压力发生变化时,按钮就会发送动作消息。

Buttons can either have two states (on and off) or three states (on, off, and mixed). You enable a three-state button by calling the allowsMixedState method. On and off states (also referred to as alternate and normal) indicate that the button is either clicked or not clicked. Mixed state is typically used for checkboxes or radio buttons  which allow for an additional intermediate state. For example, suppose the state of a checkbox denotes whether a text field contains bold text. If all of the text in the text field is bold, then the checkbox is on. If none of the text is bold, then the checkbox is off. If some of the text is bold, then the checkbox is mixed.

一个按钮可能会有两种状态(开启或关闭),甚至三种状态(开启,关闭,以及混合)。可以通过调用allowsMixedState方法来唤醒按钮的第三种状态。开启或关闭状态(也有相关文档表示为可选状态和正常状态)表明这个按钮是被点击还是未被点击。按钮的混合状态常用在复选框按钮或单选按钮上,这种状态可以当作是一种增加的过度状态。例如,假如用一个复选框来表示一个文本框里是否有粗体文字。如果这个文本框里的所有文字都是粗体的,那么这个复选框就是开启状态。相反,如果文本框中没有任何粗体文字,那么这个复选框就是关闭状态。如果文本框中有一些文字是粗体的,那么这个复选框就是混合状态。

For most types of buttons, the value of the button matches its state—the value is 1 for on, 0 for off, or -1 for mixed. For pressure-sensitive buttons, the value of the button indicates pressure level instead.

对于大多数类型的按钮,按钮的每一种状态对应相应的值,值为1表示开启状态,值为0表示关闭状态,值为-1表示混合状态。对于压力敏感类的按钮,按钮值的变化可表示压力值。

NSButton and NSMatrix both provide a control view, which displays an NSButtonCell object. However, while a matrix requires you to access the button cell objects directly, most button class methods act as "covers"  for identically declared button cell methods. In other words, the implementation of the button method invokes the corresponding button cell method for you, allowing you to be unconcerned with the existence of the button cell. The only button cell methods that don't have covers relate to the font used to display the key equivalent and to specific methods for highlighting or showing the state of the button.

NSButton类和NSMatrix类两者都能提供控制视图,并展示一个NSButtonCell对象。但是当一个NSMatrix对象需要直接接入NSButtonCell对象时,通常NSButton类的方法会被NSButtonCell类的方法覆盖。换句话说,实现NSButton类的方法时,实际调用的是NSButtonCell类相关的方法,这样在使用的时候就不会注意到NSButtonCell类的存在。NSButtonCell类方法唯一没有覆盖的是字体相关的,比如显示关键字,高亮字体的方法,或者显示按钮的状态的方法。

你可能感兴趣的:(Mac OS AppKit文档翻译——NSButton)