---
title: NSControl
framework: appkit
role: symbol
role_heading: Class
path: appkit/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.

## Declaration

```swift
class NSControl
```

## Overview

Overview The 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: controlTextDidBeginEditing:, controlTextDidChange:, and 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 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:). This method highlights the receiver’s cell and sends it a 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:) 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:)](appkit/nscontrol/init(frame:).md)
- [init(coder:)](appkit/nscontrol/init(coder:).md)

### Enabling and Disabling the Control

- [isEnabled](appkit/nscontrol/isenabled.md)

### Accessing the Control’s Value

- [doubleValue](appkit/nscontrol/doublevalue.md)
- [floatValue](appkit/nscontrol/floatvalue.md)
- [intValue](appkit/nscontrol/intvalue.md)
- [integerValue](appkit/nscontrol/integervalue.md)
- [objectValue](appkit/nscontrol/objectvalue.md)
- [stringValue](appkit/nscontrol/stringvalue.md)
- [attributedStringValue](appkit/nscontrol/attributedstringvalue.md)

### Interacting with Other Controls

- [takeDoubleValueFrom(_:)](appkit/nscontrol/takedoublevaluefrom(_:).md)
- [takeFloatValueFrom(_:)](appkit/nscontrol/takefloatvaluefrom(_:).md)
- [takeIntValueFrom(_:)](appkit/nscontrol/takeintvaluefrom(_:).md)
- [takeIntegerValueFrom(_:)](appkit/nscontrol/takeintegervaluefrom(_:).md)
- [takeObjectValueFrom(_:)](appkit/nscontrol/takeobjectvaluefrom(_:).md)
- [takeStringValueFrom(_:)](appkit/nscontrol/takestringvaluefrom(_:).md)

### Formatting Text

- [alignment](appkit/nscontrol/alignment.md)
- [font](appkit/nscontrol/font.md)
- [lineBreakMode](appkit/nscontrol/linebreakmode.md)
- [usesSingleLineMode](appkit/nscontrol/usessinglelinemode.md)
- [formatter](appkit/nscontrol/formatter.md)
- [baseWritingDirection](appkit/nscontrol/basewritingdirection.md)

### Managing Expansion Tool Tips

- [draw(withExpansionFrame:in:)](appkit/nscontrol/draw(withexpansionframe:in:).md)
- [allowsExpansionToolTips](appkit/nscontrol/allowsexpansiontooltips.md)
- [expansionFrame(withFrame:)](appkit/nscontrol/expansionframe(withframe:).md)

### Managing the Field Editor

- [abortEditing()](appkit/nscontrol/abortediting().md)
- [currentEditor()](appkit/nscontrol/currenteditor().md)
- [validateEditing()](appkit/nscontrol/validateediting().md)
- [edit(withFrame:editor:delegate:event:)](appkit/nscontrol/edit(withframe:editor:delegate:event:).md)
- [endEditing(_:)](appkit/nscontrol/endediting(_:).md)
- [select(withFrame:editor:delegate:start:length:)](appkit/nscontrol/select(withframe:editor:delegate:start:length:).md)

### Control-Editing Notifications

- [textDidBeginEditingNotification](appkit/nscontrol/textdidbegineditingnotification.md)
- [textDidChangeNotification](appkit/nscontrol/textdidchangenotification.md)
- [textDidEndEditingNotification](appkit/nscontrol/textdidendeditingnotification.md)

### Resizing the Control

- [controlSize](appkit/nscontrol/controlsize-swift.property.md)
- [NSControl.ControlSize](appkit/nscontrol/controlsize-swift.enum.md)
- [sizeThatFits(_:)](appkit/nscontrol/sizethatfits(_:).md)
- [sizeToFit()](appkit/nscontrol/sizetofit().md)

### Displaying a Cell

- [isHighlighted](appkit/nscontrol/ishighlighted.md)
- [NSControl.ImagePosition](appkit/nscontrol/imageposition.md)
- [NSControl.StateValue](appkit/nscontrol/statevalue.md)

### Implementing the Target-Action Mechanism

- [action](appkit/nscontrol/action.md)
- [target](appkit/nscontrol/target.md)
- [isContinuous](appkit/nscontrol/iscontinuous.md)
- [sendAction(_:to:)](appkit/nscontrol/sendaction(_:to:).md)
- [sendAction(on:)](appkit/nscontrol/sendaction(on:).md)

### Handling Control Events

- [NSControl.Events](appkit/nscontrol/events.md)
- [addTarget(_:action:for:)](appkit/nscontrol/addtarget(_:action:for:).md)
- [removeTarget(_:action:for:)](appkit/nscontrol/removetarget(_:action:for:).md)

### Accessing Tags

- [tag](appkit/nscontrol/tag.md)

### Activating from the Keyboard

- [performClick(_:)](appkit/nscontrol/performclick(_:).md)
- [refusesFirstResponder](appkit/nscontrol/refusesfirstresponder.md)

### Tracking the Mouse

- [mouseDown(with:)](appkit/nsresponder/mousedown(with:).md)
- [ignoresMultiClick](appkit/nscontrol/ignoresmulticlick.md)

### Supporting Constraint-Based Layout

- [invalidateIntrinsicContentSize(for:)](appkit/nscontrol/invalidateintrinsiccontentsize(for:).md)

### Deprecated

- [Deprecated Symbols](appkit/nscontrol-deprecated-symbols.md)

### Structures

- [NSControl.TextDidBeginEditingMessage](appkit/nscontrol/textdidbegineditingmessage.md)
- [NSControl.TextDidChangeMessage](appkit/nscontrol/textdidchangemessage.md)
- [NSControl.TextDidEndEditingMessage](appkit/nscontrol/textdidendeditingmessage.md)

## Relationships

### Inherits From

- [NSView](appkit/nsview.md)

### Inherited By

- [NSBrowser](appkit/nsbrowser.md)
- [NSButton](appkit/nsbutton.md)
- [NSColorWell](appkit/nscolorwell.md)
- [NSComboButton](appkit/nscombobutton.md)
- [NSDatePicker](appkit/nsdatepicker.md)
- [NSImageView](appkit/nsimageview.md)
- [NSLevelIndicator](appkit/nslevelindicator.md)
- [NSMatrix](appkit/nsmatrix.md)
- [NSPathControl](appkit/nspathcontrol.md)
- [NSRuleEditor](appkit/nsruleeditor.md)
- [NSScroller](appkit/nsscroller.md)
- [NSSegmentedControl](appkit/nssegmentedcontrol.md)
- [NSSlider](appkit/nsslider.md)
- [NSStepper](appkit/nsstepper.md)
- [NSSwitch](appkit/nsswitch.md)
- [NSTableView](appkit/nstableview.md)
- [NSTextField](appkit/nstextfield.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSAccessibilityElementProtocol](appkit/nsaccessibilityelementprotocol.md)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### View fundamentals

- [NSView](appkit/nsview.md)
- [NSCell](appkit/nscell.md)
- [NSActionCell](appkit/nsactioncell.md)
