<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISegmentedControl",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISegmentedControl"
  },
  "title" : "UISegmentedControl"
}
-->

# UISegmentedControl

A horizontal control that consists of multiple segments, each segment functioning as a discrete button.

```
@MainActor class UISegmentedControl
```

## Overview

A segmented control can display a title (an <doc://com.apple.documentation/documentation/Foundation/NSString> object) or an image ([`UIImage`](/documentation/UIKit/UIImage) object). The [`UISegmentedControl`](/documentation/UIKit/UISegmentedControl) object automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When you add and remove segments, you can request that the action be animated with sliding and fading effects.

You register the target-action methods for a segmented control using the [`valueChanged`](/documentation/UIKit/UIControl/Event/valueChanged) constant as shown below.

```swift
segmentedControl.addTarget(self, action: "action:", forControlEvents: .valueChanged)
```

How you configure a segmented control can affect its display behavior:

- If you set a segmented control to have a momentary style, a segment doesn’t show itself as selected (blue background) when the user touches it. The disclosure button is always momentary and doesn’t affect the actual selection.
- In versions of iOS prior to 3.0, if a segmented control has only two segments, then it behaves like a switch — tapping the currently-selected segment causes the other segment to be selected. In iOS 3.0 and later, tapping the currently-selected segment doesn’t cause the other segment to be selected.

### Customize appearance

You can customize the appearance of segmented controls using the methods listed in [`Customizing appearance`](/documentation/UIKit/UISegmentedControl#Customizing-appearance). You can customize the appearance of all segmented controls using the appearance proxy (for example, `[UISegmentedControl appearance]`), or just of a single control.

When customizing appearance, in general, you should specify a value for the normal state of a property to be used by other states which don’t have a custom value set. Similarly, when a property is dependent on the bar metrics (on the iPhone in landscape orientation, bars have a different height from standard), you should make sure you specify a value for [`UIBarMetrics.default`](/documentation/UIKit/UIBarMetrics/default).

In the case of the segmented control, appearance properties for [`landscapePhone`](/documentation/UIKit/UIBarMetrics/landscapePhone) are only respected for segmented controls in the smaller navigation and toolbars that are used in landscape orientation on the iPhone.

To provide complete customization, you need to provide divider images for different state combinations, using [`setDividerImage(_:forLeftSegmentState:rightSegmentState:barMetrics:)`](/documentation/UIKit/UISegmentedControl/setDividerImage(_:forLeftSegmentState:rightSegmentState:barMetrics:)):

```swift
// Image between two unselected segments.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
                                   rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
 
// Image between segment selected on the left and unselected on the right.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Selected,
                                   rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
 
// Image between segment selected on the right and unselected on the left.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
                                   rightSegmentState: UIControlState.Selected, barMetrics: UIBarMetrics.Default)
```

## Topics

### Creating a segmented control

[`init(items:)`](/documentation/UIKit/UISegmentedControl/init(items:))

Creates a segmented control with segments having the given titles or images.

[`init(frame:actions:)`](/documentation/UIKit/UISegmentedControl/init(frame:actions:))

Creates a segmented control with the given frame and adds segments for the actions you specify.

[`init(frame:)`](/documentation/UIKit/UISegmentedControl/init(frame:))

Creates an empty segmented control with the frame you specify.

[`init(coder:)`](/documentation/UIKit/UISegmentedControl/init(coder:))

Creates a segmented control with data from an unarchiver.

### Managing segment content

[`setImage(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setImage(_:forSegmentAt:))

Sets the content of a segment to a given image.

[`imageForSegment(at:)`](/documentation/UIKit/UISegmentedControl/imageForSegment(at:))

Returns the image for a specific segment.

[`setTitle(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setTitle(_:forSegmentAt:))

Sets the title of a segment.

[`titleForSegment(at:)`](/documentation/UIKit/UISegmentedControl/titleForSegment(at:))

Returns the title of the specified segment.

### Managing segment actions

[`actionForSegment(at:)`](/documentation/UIKit/UISegmentedControl/actionForSegment(at:))

Fetches the action of the segment at the index you specify, if one exists.

[`setAction(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setAction(_:forSegmentAt:))

Sets the action for the segment at the index you specify.

### Managing segments

[`numberOfSegments`](/documentation/UIKit/UISegmentedControl/numberOfSegments)

Returns the number of segments the segmented control has.

[`segmentIndex(identifiedBy:)`](/documentation/UIKit/UISegmentedControl/segmentIndex(identifiedBy:))

The index of a segment with an action that has an identifier matching the identifier you specify.

[`insertSegment(action:at:animated:)`](/documentation/UIKit/UISegmentedControl/insertSegment(action:at:animated:))

Insert a segment with the action you specify at the given index.

[`insertSegment(with:at:animated:)`](/documentation/UIKit/UISegmentedControl/insertSegment(with:at:animated:))

Inserts a segment at the position you specify and gives it an image as content.

[`insertSegment(withTitle:at:animated:)`](/documentation/UIKit/UISegmentedControl/insertSegment(withTitle:at:animated:))

Inserts a segment at the position you specify and gives it a title as content.

[`removeAllSegments()`](/documentation/UIKit/UISegmentedControl/removeAllSegments())

Removes all segments of the segmented control.

[`removeSegment(at:animated:)`](/documentation/UIKit/UISegmentedControl/removeSegment(at:animated:))

Removes the segment you specify from the segmented control, optionally animating the transition.

[`selectedSegmentIndex`](/documentation/UIKit/UISegmentedControl/selectedSegmentIndex)

The index number that identifies the selected segment that the user last touched.

[`noSegment`](/documentation/UIKit/UISegmentedControl/noSegment)

A segment index value indicating that there’s no selected segment.

### Managing segment behavior and appearance

[`isMomentary`](/documentation/UIKit/UISegmentedControl/isMomentary)

A Boolean value that determines whether segments in the segmented control show selected state.

[`setEnabled(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setEnabled(_:forSegmentAt:))

Enables the segment you specify.

[`isEnabledForSegment(at:)`](/documentation/UIKit/UISegmentedControl/isEnabledForSegment(at:))

Returns whether the indicated segment is enabled.

[`setContentOffset(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setContentOffset(_:forSegmentAt:))

Adjusts the offset for drawing the content (image or text) of the specified segment.

[`contentOffsetForSegment(at:)`](/documentation/UIKit/UISegmentedControl/contentOffsetForSegment(at:))

Returns the offset for drawing the content (image or text) of the segment you specify.

[`setWidth(_:forSegmentAt:)`](/documentation/UIKit/UISegmentedControl/setWidth(_:forSegmentAt:))

Sets the width of the segment at the index you specify.

[`widthForSegment(at:)`](/documentation/UIKit/UISegmentedControl/widthForSegment(at:))

Returns the width of the segment at the index you specify.

[`apportionsSegmentWidthsByContent`](/documentation/UIKit/UISegmentedControl/apportionsSegmentWidthsByContent)

Indicates whether the control attempts to adjust segment widths based on their content widths.

[`segmentedControlStyle`](/documentation/UIKit/UISegmentedControl/segmentedControlStyle)

The style of the segmented control.

[`UISegmentedControlStyle`](/documentation/UIKit/UISegmentedControlStyle)

The styles of the segmented control.

### Customizing appearance

[`selectedSegmentTintColor`](/documentation/UIKit/UISegmentedControl/selectedSegmentTintColor)

The color to use for highlighting the currently selected segment.

[`backgroundImage(for:barMetrics:)`](/documentation/UIKit/UISegmentedControl/backgroundImage(for:barMetrics:))

Returns the background image for a given state and bar metrics.

[`setBackgroundImage(_:for:barMetrics:)`](/documentation/UIKit/UISegmentedControl/setBackgroundImage(_:for:barMetrics:))

Sets the background image for given state and bar metrics.

[`contentPositionAdjustment(forSegmentType:barMetrics:)`](/documentation/UIKit/UISegmentedControl/contentPositionAdjustment(forSegmentType:barMetrics:))

Returns the positioning offset for a given segment and bar metrics.

[`setContentPositionAdjustment(_:forSegmentType:barMetrics:)`](/documentation/UIKit/UISegmentedControl/setContentPositionAdjustment(_:forSegmentType:barMetrics:))

Sets the content positioning offset for a given segment and bar metrics.

[`UISegmentedControl.Segment`](/documentation/UIKit/UISegmentedControl/Segment)

Constants for specifying a segment in a control.

[`dividerImage(forLeftSegmentState:rightSegmentState:barMetrics:)`](/documentation/UIKit/UISegmentedControl/dividerImage(forLeftSegmentState:rightSegmentState:barMetrics:))

Returns the divider image used for a given combination of left and right segment states and bar metrics.

[`setDividerImage(_:forLeftSegmentState:rightSegmentState:barMetrics:)`](/documentation/UIKit/UISegmentedControl/setDividerImage(_:forLeftSegmentState:rightSegmentState:barMetrics:))

Sets the divider image to use for a given combination of left and right segment states and bar metrics.

[`titleTextAttributes(for:)`](/documentation/UIKit/UISegmentedControl/titleTextAttributes(for:))

Returns the text attributes of the title for a given control state.

[`setTitleTextAttributes(_:for:)`](/documentation/UIKit/UISegmentedControl/setTitleTextAttributes(_:for:))

Sets the text attributes of the title for a given control state.



---

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)