Class

NSSegmentedControl

An NSSegmentedControl object implements a linear set of two or more segments, each of which functions as a button.

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 NSSegmentSwitchTracking. 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.

Symbols

Specifying Tracking Behavior

var trackingMode: NSSegmentSwitchTracking

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: NSSegmentStyle

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

NSSegmentSwitchTracking

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

NSSegmentStyle

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

Relationships

Inherits From

Conforms To