<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISegmentedControl/insertSegment(action:at:animated:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISegmentedControl(im)insertSegmentWithAction:atIndex:animated:"
  },
  "title" : "insertSegment(action:at:animated:)"
}
-->

# insertSegment(action:at:animated:)

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

```
func insertSegment(action: UIAction, at segment: Int, animated: Bool)
```

## Parameters

`action`

A [`UIAction`](/documentation/UIKit/UIAction) object to set on the segment at the index you specify.

`segment`

An unsigned integer index of a segment.

`animated`

<doc://com.apple.documentation/documentation/Swift/true> if the insertion of the new segment animates; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Segments prefer images over titles when the action contains both. Selecting a segment invokes the action’s [`UIActionHandler`](/documentation/UIKit/UIActionHandler), as well as handlers for the [`valueChanged`](/documentation/UIKit/UIControl/Event/valueChanged) and [`primaryActionTriggered`](/documentation/UIKit/UIControl/Event/primaryActionTriggered) control events.

If a segment exists with the action’s identifier, this method updates the existing segment is if the index is the same or removes the segment if the index is different.

---

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)