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

# width(forSegment:)

Returns the width of the specified segment.

## Declaration

```swift
func width(forSegment segment: Int) -> CGFloat
```

## Parameters

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

## Return Value

Return Value The width of the segment, measured in points, or 0 if the segment is sized to fit the available space automatically.

## See Also

### Adjusting the segment spacing

- [setWidth(_:forSegment:)](appkit/nssegmentedcontrol/setwidth(_: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)
