---
title: "setImage(_:forSegment:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nssegmentedcontrol/setimage(_:forsegment:)"
---

# setImage(_:forSegment:)

Sets the image for the specified segment.

## Declaration

```swift
func setImage(_ image: NSImage?, forSegment segment: Int)
```

## Parameters

- `image`: The image to apply to the segment or nil if you want to clear the existing image. Images are not scaled to fit inside a segment. If the image is larger than the available space, it is clipped.
- `segment`: The index of the segment whose image you want to set. This method raises an exception (doc://com.apple.documentation/documentation/Foundation/NSExceptionName/rangeException) if the index is out of bounds.

## See Also

### Configuring a segment image

- [image(forSegment:)](appkit/nssegmentedcontrol/image(forsegment:).md)
- [setImageScaling(_:forSegment:)](appkit/nssegmentedcontrol/setimagescaling(_:forsegment:).md)
- [imageScaling(forSegment:)](appkit/nssegmentedcontrol/imagescaling(forsegment:).md)
