---
title: "setImage(_:forSegmentAt:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uisegmentedcontrol/setimage(_:forsegmentat:)"
---

# setImage(_:forSegmentAt:)

Sets the content of a segment to a given image.

## Declaration

```swift
func setImage(_ image: UIImage?, forSegmentAt segment: Int)
```

## Parameters

- `image`: An image object to display in the segment.
- `segment`: An index number identifying a segment in the control. It must be a number between 0 and the number of segments (doc://com.apple.uikit/documentation/UIKit/UISegmentedControl/numberOfSegments) minus 1; the segmented control pins values exceeding this upper range to the last segment.

## Discussion

Discussion A segment can have only an image or a title; it can’t have both. There’s no default image.

## See Also

### Managing segment content

- [imageForSegment(at:)](uikit/uisegmentedcontrol/imageforsegment(at:).md)
- [setTitle(_:forSegmentAt:)](uikit/uisegmentedcontrol/settitle(_:forsegmentat:).md)
- [titleForSegment(at:)](uikit/uisegmentedcontrol/titleforsegment(at:).md)
