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

# setWidth(_:forSegment:)

Sets the width of the specified segment.

```
func setWidth(_ width: CGFloat, forSegment segment: Int)
```

## Parameters

`width`

The width of the segment, measured in points. Specify the value `0` if you want the segment to be sized to fit the available space automatically.

`segment`

The index of the segment whose width you want to set. This method raises an exception (<doc://com.apple.documentation/documentation/Foundation/NSExceptionName/rangeException>) if the index is out of bounds.

---

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)