---
title: "setWidth(_:forSegmentAt:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uisegmentedcontrol/setwidth(_:forsegmentat:)"
---

# setWidth(_:forSegmentAt:)

Sets the width of the segment at the index you specify.

## Declaration

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

## Parameters

- `width`: A float value specifying the width of the segment. The default value is {0.0}, which tells UISegmentedControl to automatically size the segment.
- `segment`: An index number identifying a segment in the control. It must be a number between 0 and the number of segments (doc://com.apple.uikit/documentation/UIKit/UISegmentedControl/numberOfSegments) minus 1; the segmented control pins values exceeding this upper range to the last segment.

## See Also

### Managing segment behavior and appearance

- [isMomentary](uikit/uisegmentedcontrol/ismomentary.md)
- [setEnabled(_:forSegmentAt:)](uikit/uisegmentedcontrol/setenabled(_:forsegmentat:).md)
- [isEnabledForSegment(at:)](uikit/uisegmentedcontrol/isenabledforsegment(at:).md)
- [setContentOffset(_:forSegmentAt:)](uikit/uisegmentedcontrol/setcontentoffset(_:forsegmentat:).md)
- [contentOffsetForSegment(at:)](uikit/uisegmentedcontrol/contentoffsetforsegment(at:).md)
- [widthForSegment(at:)](uikit/uisegmentedcontrol/widthforsegment(at:).md)
- [apportionsSegmentWidthsByContent](uikit/uisegmentedcontrol/apportionssegmentwidthsbycontent.md)
