---
title: "insertSegment(with:at:animated:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uisegmentedcontrol/insertsegment(with:at:animated:)"
---

# insertSegment(with:at:animated:)

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

## Declaration

```swift
func insertSegment(with image: UIImage?, at segment: Int, animated: Bool)
```

## Parameters

- `image`: An image object to use as the content of the segment.
- `segment`: An index number identifying a segment in the control. segment must be a number in the range 0 to the number of segments (doc://com.apple.uikit/documentation/UIKit/UISegmentedControl/numberOfSegments) inclusive; the segmented control pins values exceeding this upper range to the last segment. The segmented control inserts the new segment immediately before the designated one.
- `animated`: doc://com.apple.documentation/documentation/Swift/true if the insertion of the new segment must animate; otherwise, doc://com.apple.documentation/documentation/Swift/false.

## See Also

### Managing segments

- [numberOfSegments](uikit/uisegmentedcontrol/numberofsegments.md)
- [segmentIndex(identifiedBy:)](uikit/uisegmentedcontrol/segmentindex(identifiedby:).md)
- [insertSegment(action:at:animated:)](uikit/uisegmentedcontrol/insertsegment(action:at:animated:).md)
- [insertSegment(withTitle:at:animated:)](uikit/uisegmentedcontrol/insertsegment(withtitle:at:animated:).md)
- [removeAllSegments()](uikit/uisegmentedcontrol/removeallsegments().md)
- [removeSegment(at:animated:)](uikit/uisegmentedcontrol/removesegment(at:animated:).md)
- [selectedSegmentIndex](uikit/uisegmentedcontrol/selectedsegmentindex.md)
- [noSegment](uikit/uisegmentedcontrol/nosegment.md)
