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

# setWidth(_:forSegment:)

Sets the width of the specified segment.

## Declaration

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

## See Also

### Adjusting the segment spacing

- [width(forSegment:)](appkit/nssegmentedcontrol/width(forsegment:).md)
- [segmentDistribution](appkit/nssegmentedcontrol/segmentdistribution.md)
- [NSSegmentedControl.Distribution](appkit/nssegmentedcontrol/distribution.md)
- [activeCompressionOptions](appkit/nssegmentedcontrol/activecompressionoptions.md)
- [compress(withPrioritizedCompressionOptions:)](appkit/nssegmentedcontrol/compress(withprioritizedcompressionoptions:).md)
- [minimumSize(withPrioritizedCompressionOptions:)](appkit/nssegmentedcontrol/minimumsize(withprioritizedcompressionoptions:).md)
