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

# drawSegment(_:inFrame:with:)

Draws the image and label of the segment in the specified view.

```
func drawSegment(_ segment: Int, inFrame frame: NSRect, with controlView: NSView)
```

## Parameters

`segment`

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

`frame`

The rectangle in which to draw the segment’s image and label. This rectangle is specified in user space coordinates of the specified view.

`controlView`

The view that contains the segment.

## Discussion

You can override this method to provide a custom appearance for segmented controls. You should not call this method directly. It is called for you automatically by the control when it needs to be redrawn.

## See Also

[`func draw(withFrame: NSRect, in: NSView)`](/documentation/AppKit/NSCell/draw(withFrame:in:))

Draws the receiver’s border and then draws the interior of the cell.



---

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)