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

# NSSegmentedControl

Display one or more buttons in a single horizontal group.

```
class NSSegmentedControl
```

## Overview

The `NSSegmentedControl` class uses an [`NSSegmentedCell`](/documentation/AppKit/NSSegmentedCell) class to implement much of the control’s functionality. Most methods in `NSSegmentedControl` are simply cover methods that call the corresponding method in [`NSSegmentedCell`](/documentation/AppKit/NSSegmentedCell). The methods of [`NSSegmentedCell`](/documentation/AppKit/NSSegmentedCell) that do not have covers relate to accessing and setting values for tags and tooltips, programatically setting the key segment, and establishing the mode of the control.

The features of a segmented control include the following:

- A segment can have an image, text (label), menu, tooltip, and tag.
- A segmented control can contain images or text, but not both.
- Either the control or individual segments can be enabled or disabled.
- Segmented controls have four tracking modes, described in [`NSSegmentedControl.SwitchTracking`](/documentation/AppKit/NSSegmentedControl/SwitchTracking). You use these modes with the [`trackingMode`](/documentation/AppKit/NSSegmentedControl/trackingMode) property.
- Each segment can be either a fixed width or autosized to fit the contents.
- If a segment has text and is marked as autosizing, then the text may be truncated so that the control completely fits.
- If an image is too large to fit in a segment, it is clipped.
- If Full Keyboard Access is enabled in System Preferences > Keyboard, the keyboard may be used to move between and select segments.

## Topics

### Creating a segmented control

[`init(images:trackingMode:target:action:)`](/documentation/AppKit/NSSegmentedControl/init(images:trackingMode:target:action:))

Creates a standard segmented control containing one segment for each of the provided images.

[`init(labels:trackingMode:target:action:)`](/documentation/AppKit/NSSegmentedControl/init(labels:trackingMode:target:action:))

Creates a standard segmented control containing one segment for each of the provided labels.

### Configuring the cell

[`NSSegmentedCell`](/documentation/AppKit/NSSegmentedCell)

An `NSSegmentedCell` object implements the appearance and behavior of a horizontal button divided into multiple segments. This class is used in conjunction with the [`NSSegmentedControl`](/documentation/AppKit/NSSegmentedControl) class to implement a segmented control.

### Specifying the segment behavior

[`trackingMode`](/documentation/AppKit/NSSegmentedControl/trackingMode)

The type of tracking behavior the control exhibits.

[`NSSegmentedControl.SwitchTracking`](/documentation/AppKit/NSSegmentedControl/SwitchTracking)

Constants that specify the type of tracking behavior a segmented control exhibits.

[`segmentStyle`](/documentation/AppKit/NSSegmentedControl/segmentStyle)

The visual style used to display the control.

[`NSSegmentedControl.Style`](/documentation/AppKit/NSSegmentedControl/Style)

The following constants specify the visual style used to display the segmented control. They are used by [`segmentStyle`](/documentation/AppKit/NSSegmentedControl/segmentStyle).

[`role`](/documentation/AppKit/NSSegmentedControl/role-swift.property)

[`NSSegmentedControl.Role`](/documentation/AppKit/NSSegmentedControl/Role-swift.enum)

### Specifying number of segments

[`segmentCount`](/documentation/AppKit/NSSegmentedControl/segmentCount)

The number of segments in the control.

### Configuring the segment text

[`label(forSegment:)`](/documentation/AppKit/NSSegmentedControl/label(forSegment:))

Returns the label of the specified segment.

[`setLabel(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setLabel(_:forSegment:))

Sets the label for the specified segment.

[`setAlignment(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setAlignment(_:forSegment:))

[`alignment(forSegment:)`](/documentation/AppKit/NSSegmentedControl/alignment(forSegment:))

### Configuring a segment image

[`setImage(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setImage(_:forSegment:))

Sets the image for the specified segment.

[`image(forSegment:)`](/documentation/AppKit/NSSegmentedControl/image(forSegment:))

Returns the image associated with the specified segment.

[`setImageScaling(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setImageScaling(_:forSegment:))

Sets the scaling mode used to display the specified segment’s image.

[`imageScaling(forSegment:)`](/documentation/AppKit/NSSegmentedControl/imageScaling(forSegment:))

Returns the scaling mode used to display the specified segment’s image.

### Configuring a segment menu

[`setMenu(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setMenu(_:forSegment:))

Sets the menu for the specified segment.

[`menu(forSegment:)`](/documentation/AppKit/NSSegmentedControl/menu(forSegment:))

Returns the menu for the specified segment.

[`setShowsMenuIndicator(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setShowsMenuIndicator(_:forSegment:))

[`showsMenuIndicator(forSegment:)`](/documentation/AppKit/NSSegmentedControl/showsMenuIndicator(forSegment:))

[`isSpringLoaded`](/documentation/AppKit/NSSegmentedControl/isSpringLoaded)

A Boolean value that indicates whether spring loading is enabled for the control.

### Managing the selected segment

[`selectedSegment`](/documentation/AppKit/NSSegmentedControl/selectedSegment)

The index of the selected segment of the control, or `-1` if no segment is selected.

[`indexOfSelectedItem`](/documentation/AppKit/NSSegmentedControl/indexOfSelectedItem)

[`selectSegment(withTag:)`](/documentation/AppKit/NSSegmentedControl/selectSegment(withTag:))

Selects the segment with the specified tag.

[`setSelected(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setSelected(_:forSegment:))

Sets the selection state of the specified segment.

[`isSelected(forSegment:)`](/documentation/AppKit/NSSegmentedControl/isSelected(forSegment:))

Returns a Boolean value indicating whether the specified segment is selected.

[`selectedSegmentBezelColor`](/documentation/AppKit/NSSegmentedControl/selectedSegmentBezelColor)

The color of the selected segment’s bezel, in appearances that support it.

[`doubleValueForSelectedSegment`](/documentation/AppKit/NSSegmentedControl/doubleValueForSelectedSegment)

When the tracking mode for the control is set to use a momentary accelerator, returns a value for the selected segment.

### Adjusting the segment spacing

[`setWidth(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setWidth(_:forSegment:))

Sets the width of the specified segment.

[`width(forSegment:)`](/documentation/AppKit/NSSegmentedControl/width(forSegment:))

Returns the width of the specified segment.

[`segmentDistribution`](/documentation/AppKit/NSSegmentedControl/segmentDistribution)

[`NSSegmentedControl.Distribution`](/documentation/AppKit/NSSegmentedControl/Distribution)

[`activeCompressionOptions`](/documentation/AppKit/NSSegmentedControl/activeCompressionOptions)

[`compress(withPrioritizedCompressionOptions:)`](/documentation/AppKit/NSSegmentedControl/compress(withPrioritizedCompressionOptions:))

[`minimumSize(withPrioritizedCompressionOptions:)`](/documentation/AppKit/NSSegmentedControl/minimumSize(withPrioritizedCompressionOptions:))

### Specifying the border shape

[`borderShape`](/documentation/AppKit/NSSegmentedControl/borderShape)

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

### Enabling and disabling segments

[`setEnabled(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setEnabled(_:forSegment:))

Sets the enabled state of the specified segment

[`isEnabled(forSegment:)`](/documentation/AppKit/NSSegmentedControl/isEnabled(forSegment:))

Returns a Boolean value indicating whether the specified segment is enabled.

### Managing tags and tooltips

[`tag(forSegment:)`](/documentation/AppKit/NSSegmentedControl/tag(forSegment:))

[`setTag(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setTag(_:forSegment:))

[`setToolTip(_:forSegment:)`](/documentation/AppKit/NSSegmentedControl/setToolTip(_:forSegment:))

[`toolTip(forSegment:)`](/documentation/AppKit/NSSegmentedControl/toolTip(forSegment:))



---

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)