Class

NSSegmentedControl

Display one or more buttons in a single horizontal group.

Overview

The NSSegmentedControl class uses an 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. The methods of 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. You use these modes with the 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

Configuring the Cell

class 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 class to implement a segmented control.

Specifying Tracking Behavior

var trackingMode: NSSegmentedControl.SwitchTracking

The type of tracking behavior the control exhibits.

Specifying Number of Segments

var segmentCount: Int

The number of segments in the control.

Specifying Selected Segment

var selectedSegment: Int

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

func selectSegment(withTag: Int)

Selects the segment with the specified tag.

Working with Selected Segments

var doubleValueForSelectedSegment: Double

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

Working with Individual Segments

func setWidth(CGFloat, forSegment: Int)

Sets the width of the specified segment.

func width(forSegment: Int)

Returns the width of the specified segment.

func setImage(NSImage?, forSegment: Int)

Sets the image for the specified segment.

func image(forSegment: Int)

Returns the image associated with the specified segment.

func setLabel(String, forSegment: Int)

Sets the label for the specified segment.

func label(forSegment: Int)

Returns the label of the specified segment.

func setMenu(NSMenu?, forSegment: Int)

Sets the menu for the specified segment.

func menu(forSegment: Int)

Returns the menu for the specified segment.

func setSelected(Bool, forSegment: Int)

Sets the selection state of the specified segment.

func isSelected(forSegment: Int)

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

func setEnabled(Bool, forSegment: Int)

Sets the enabled state of the specified segment

func isEnabled(forSegment: Int)

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

var isSpringLoaded: Bool

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

Specifying Segment Display

var segmentStyle: NSSegmentedControl.Style

The visual style used to display the control.

func setImageScaling(NSImageScaling, forSegment: Int)

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

func imageScaling(forSegment: Int)

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

Constants

enum NSSegmentedControl.SwitchTracking

The following constants specify the type of tracking behavior a segmented control exhibits. They are used by trackingMode.

enum NSSegmentedControl.Style

The following constants specify the visual style used to display the segmented control. They are used by segmentStyle.

Instance Properties

var selectedSegmentBezelColor: NSColor?

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

See Also

Controls

class NSButton

A control that defines an area on the screen that can be used to trigger actions.

class NSColorWell

A control that displays a color value and lets the user change that color value.

Date Picker

Display a calendar date and provide controls for editing the date value.

class NSImageView

A display of image data from an NSImage object in a frame.

class NSLevelIndicator

A visual representation of a level or quantity, using discrete values.

Path Control

A display of a file system path or virtual path information.

class NSPopUpButton

A display of a single item from a list of items, and provide an interface for selecting items from the list.

class NSProgressIndicator

An interface that provides visual feedback to the user about the status of an ongoing task.

class NSRuleEditor

An interface for configuring a rule-based list of options.

class NSPredicateEditor

A defined set of rules that allows the editing of predicate objects.

Search Field

Provide a text field that is optimized for text-based search interfaces.

Slider

Display a range of values from which the user selects a single value.

class NSStepper

An interface with up and down arrow buttons for incrementing or decrementing a value.

Text Field

Provide a simple interface for displaying and editing text, including support for password fields and secure forms of text entry.

Token Field

Provide a text field whose text can be rendered in a visually distinct way so that users can recognize portions more easily.

Toolbar

Provide a space for controls under a window's title bar and above your custom content.

Combo Box

Display a list of values in a pop-up menu that lets the user select a value or type in a custom value.

class NSMatrix

A legacy interface for grouping radio buttons or other types of cells together.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software