<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSegmentedControl/setImage(_:forSegment:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSegmentedControl(im)setImage:forSegment:"
  },
  "title" : "setImage(_:forSegment:)"
}
-->

# setImage(_:forSegment:)

Sets the image for the specified segment.

```
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.

## Discussion

---

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)