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

# setLabel(_:forSegment:)

Sets the label for the specified segment.

```
func setLabel(_ label: String, forSegment segment: Int)
```

## Parameters

`label`

The label you want to display in the segment. If the width of the string is greater than the width of the segment, the string’s text is truncated during drawing.

`segment`

The index of the segment whose label 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)