<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSControl",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSControl"
  },
  "title" : "NSControl"
}
-->

# NSControl

A specialized view, such as a button or text field, that notifies your app of relevant events using the target-action design pattern.

```
class NSControl
```

## Overview

The [`NSControl`](/documentation/AppKit/NSControl) class is abstract and must be subclassed to be used. Although you can subclass it yourself, more often you use one of the subclasses already defined by AppKit. A control draws content on the screen, automatically handles user interactions with that content, and calls the action method of its target object for any significant user interactions.

### About delegate methods

The `NSControl` class provides several delegate methods for its subclasses that allow text editing, such as `NSTextField` and `NSMatrix`. These include: <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/controlTextDidBeginEditing:>, <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/controlTextDidChange:>, and <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/controlTextDidEndEditing:>.

Note that although `NSControl` defines delegate methods, it doesn’t itself have a delegate. Any subclass that uses these methods must have a delegate and the methods to get and set it. In addition, a formal delegate protocol [`NSControlTextEditingDelegate`](/documentation/AppKit/NSControlTextEditingDelegate) also defines delegate methods used by control delegates.

### Responding to mouse events

When the mouse button is pressed while the cursor is within the bounds of the receiver, the system calls [`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:)). This method highlights the receiver’s cell and sends it a [`trackMouse(with:in:of:untilMouseUp:)`](/documentation/AppKit/NSCell/trackMouse(with:in:of:untilMouseUp:)) message. Whenever the cell finishes tracking the mouse (for example, because the cursor has left the cell’s bounds), the cell is unhighlighted. If the mouse button is still down and the cursor reenters the bounds, the cell is again highlighted and a new [`trackMouse(with:in:of:untilMouseUp:)`](/documentation/AppKit/NSCell/trackMouse(with:in:of:untilMouseUp:)) message is sent. This behavior repeats until the mouse button goes up. If it goes up with the cursor in the control, the state of the control is changed, and the action message is sent to the target. If the mouse button goes up when the cursor is outside the control, no action message is sent.

## Topics

### Creating a Control

[`init(frame:)`](/documentation/AppKit/NSControl/init(frame:))

Initializes a control with the specified frame rectangle.

[`init(coder:)`](/documentation/AppKit/NSControl/init(coder:))

Initializes a control with data in an unarchiver.

### Enabling and Disabling the Control

[`isEnabled`](/documentation/AppKit/NSControl/isEnabled)

A Boolean value that indicates whether the receiver reacts to mouse events.

### Accessing the Control’s Value

[`doubleValue`](/documentation/AppKit/NSControl/doubleValue)

The value of the receiver’s cell as a double-precision floating-point number.

[`floatValue`](/documentation/AppKit/NSControl/floatValue)

The value of the receiver’s cell as a single-precision floating-point number.

[`intValue`](/documentation/AppKit/NSControl/intValue)

The value of the receiver’s cell as an integer.

[`integerValue`](/documentation/AppKit/NSControl/integerValue)

The value of the receiver’s cell as an integer value.

[`objectValue`](/documentation/AppKit/NSControl/objectValue)

The value of the receiver’s cell as an Objective-C object.

[`stringValue`](/documentation/AppKit/NSControl/stringValue)

The value of the receiver’s cell as an `NSString` object.

[`attributedStringValue`](/documentation/AppKit/NSControl/attributedStringValue)

The value of the receiver’s cell as an attributed string.

### Interacting with Other Controls

[`takeDoubleValueFrom(_:)`](/documentation/AppKit/NSControl/takeDoubleValueFrom(_:))

Sets the value of the receiver’s cell to a double-precision floating-point value obtained from the specified object.

[`takeFloatValueFrom(_:)`](/documentation/AppKit/NSControl/takeFloatValueFrom(_:))

Sets the value of the receiver’s cell to a single-precision floating-point value obtained from the specified object.

[`takeIntValueFrom(_:)`](/documentation/AppKit/NSControl/takeIntValueFrom(_:))

Sets the value of the receiver’s cell to an integer value obtained from the specified object.

[`takeIntegerValueFrom(_:)`](/documentation/AppKit/NSControl/takeIntegerValueFrom(_:))

Sets the value of the receiver’s cell to an `NSInteger` value obtained from the specified object.

[`takeObjectValueFrom(_:)`](/documentation/AppKit/NSControl/takeObjectValueFrom(_:))

Sets the value of the receiver’s cell to the object value obtained from the specified object.

[`takeStringValueFrom(_:)`](/documentation/AppKit/NSControl/takeStringValueFrom(_:))

Sets the value of the receiver’s cell to the string value obtained from the specified object.

### Formatting Text

[`alignment`](/documentation/AppKit/NSControl/alignment)

The alignment mode of the text in the receiver’s cell.

[`font`](/documentation/AppKit/NSControl/font)

The font used to draw text in the receiver’s cell.

[`lineBreakMode`](/documentation/AppKit/NSControl/lineBreakMode)

The line break mode to use for text in the control’s cell.

[`usesSingleLineMode`](/documentation/AppKit/NSControl/usesSingleLineMode)

A Boolean value that indicates whether the text in the control’s cell uses single line mode.

[`setFloatingPointFormat:left:right:`](/documentation/AppKit/NSControl/setFloatingPointFormat:left:right:)

Sets the auto-ranging and floating point number format of the receiver’s cell.

[`formatter`](/documentation/AppKit/NSControl/formatter)

The receiver’s formatter.

[`baseWritingDirection`](/documentation/AppKit/NSControl/baseWritingDirection)

The initial writing direction used to determine the actual writing direction for text.

### Managing Expansion Tool Tips

[`draw(withExpansionFrame:in:)`](/documentation/AppKit/NSControl/draw(withExpansionFrame:in:))

Performs custom expansion tool tip drawing.

[`allowsExpansionToolTips`](/documentation/AppKit/NSControl/allowsExpansionToolTips)

A Boolean value that indicates whether expansion tool tips are shown when the control is hovered over.

[`expansionFrame(withFrame:)`](/documentation/AppKit/NSControl/expansionFrame(withFrame:))

The frame in which a tool tip can be displayed, if needed.

### Managing the Field Editor

[`abortEditing()`](/documentation/AppKit/NSControl/abortEditing())

Terminates the current editing operation and discards any edited text.

[`currentEditor()`](/documentation/AppKit/NSControl/currentEditor())

Returns the current field editor for the control.

[`validateEditing()`](/documentation/AppKit/NSControl/validateEditing())

Validates changes to any user-typed text.

[`edit(withFrame:editor:delegate:event:)`](/documentation/AppKit/NSControl/edit(withFrame:editor:delegate:event:))

Begins editing of the receiver’s text using the specified field editor.

[`endEditing(_:)`](/documentation/AppKit/NSControl/endEditing(_:))

Ends the editing of text in the receiver using the specified field editor.

[`select(withFrame:editor:delegate:start:length:)`](/documentation/AppKit/NSControl/select(withFrame:editor:delegate:start:length:))

Selects the specified text range in the receiver’s field editor.

### Control-Editing Notifications

An [`NSControl`](/documentation/AppKit/NSControl)

A specialized view, such as a button or text field, that notifies your app of relevant events using the target-action design pattern. object posts the following notifications to interested observers and its delegate. Note that although the [`NSControl`](/documentation/AppKit/NSControl)

A specialized view, such as a button or text field, that notifies your app of relevant events using the target-action design pattern. class defines delegate methods, it doesn’t itself have a delegate. Any subclass that uses these methods must have a delegate and the methods to get and set it.

[`textDidBeginEditingNotification`](/documentation/AppKit/NSControl/textDidBeginEditingNotification)

Sent when a control with editable cells begins an edit session.

[`textDidChangeNotification`](/documentation/AppKit/NSControl/textDidChangeNotification)

Sent when the text in the receiving control changes.

[`textDidEndEditingNotification`](/documentation/AppKit/NSControl/textDidEndEditingNotification)

Sent when a control with editable cells ends an editing session.

### Resizing the Control

[`controlSize`](/documentation/AppKit/NSControl/controlSize-swift.property)

The size of the control.

[`NSControl.ControlSize`](/documentation/AppKit/NSControl/ControlSize-swift.enum)

A constant for specifying a cell’s size.

[`sizeThatFits(_:)`](/documentation/AppKit/NSControl/sizeThatFits(_:))

Asks the control to calculate and return the size that best fits the specified size.

[`sizeToFit()`](/documentation/AppKit/NSControl/sizeToFit())

Resizes the receiver’s frame so that it’s the minimum size needed to contain its cell.

### Displaying a Cell

[`isHighlighted`](/documentation/AppKit/NSControl/isHighlighted)

A Boolean value that indicates whether the cell is highlighted.

[`NSControl.ImagePosition`](/documentation/AppKit/NSControl/ImagePosition)

A constant for specifying the position of a button’s image relative to its title.

[`NSControl.StateValue`](/documentation/AppKit/NSControl/StateValue)

A constant that indicates whether a control is on, off, or in a mixed state.

### Implementing the Target-Action Mechanism

[`action`](/documentation/AppKit/NSControl/action)

The default action-message selector associated with the control.

[`target`](/documentation/AppKit/NSControl/target)

The target object that receives action messages from the cell.

[`isContinuous`](/documentation/AppKit/NSControl/isContinuous)

A Boolean value indicating whether the receiver’s cell sends its action message continuously to its target during mouse tracking.

[`sendAction(_:to:)`](/documentation/AppKit/NSControl/sendAction(_:to:))

Causes the specified action to be sent to the target.

[`sendAction(on:)`](/documentation/AppKit/NSControl/sendAction(on:))

Sets the conditions on which the receiver sends action messages to its target.

### Handling Control Events

[`NSControl.Events`](/documentation/AppKit/NSControl/Events)

A set of events that a control can report to its target.

[`addTarget(_:action:for:)`](/documentation/AppKit/NSControl/addTarget(_:action:for:))

Registers a target-action pair for the specified control events.

[`removeTarget(_:action:for:)`](/documentation/AppKit/NSControl/removeTarget(_:action:for:))

Stops the delivery of events to the specified target object.

### Accessing Tags

[`tag`](/documentation/AppKit/NSControl/tag)

The tag identifying the receiver (not the tag of the receiver’s cell).

### Activating from the Keyboard

[`performClick(_:)`](/documentation/AppKit/NSControl/performClick(_:))

Simulates a single mouse click on the receiver.

[`refusesFirstResponder`](/documentation/AppKit/NSControl/refusesFirstResponder)

A Boolean value indicating whether the receiver refuses the first responder role.

### Tracking the Mouse

[`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:))

Informs the receiver that the user has pressed the left mouse button.

[`ignoresMultiClick`](/documentation/AppKit/NSControl/ignoresMultiClick)

A Boolean value indicating whether the receiver ignores multiple clicks made in rapid succession.

### Supporting Constraint-Based Layout

[`invalidateIntrinsicContentSize(for:)`](/documentation/AppKit/NSControl/invalidateIntrinsicContentSize(for:))

Notifies the control that the intrinsic content size for its cell is no longer valid.

### Deprecated

[Deprecated Symbols](/documentation/AppKit/nscontrol-deprecated-symbols)

Review unsupported symbols and their replacements.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)