Mac Developer Library

Developer

AppKit Framework Reference NSSegmentedCell Class Reference

Options
Deployment Target:

On This Page
Language:

NSSegmentedCell

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.3 and later.

The NSSegmentedCell class implements the appearance and behavior of a horizontal button divided into multiple segments. This class is used in conjunction with the NSSegmentedControl class to implement a segmented control.

You can customize the attributes of a segmented control using the methods of NSSegmentedCell. To customize the appearance of individual segments, you can also subclass and override the drawSegment:inFrame:withView: method.

  • The number of segments in the receiver.

    Declaration

    Swift

    var segmentCount: Int

    Objective-C

    @property NSInteger segmentCount

    Discussion

    This property contains the number of segments the receiver should have. If this value is less than the number of segments currently in the receiver, segments are removed from the right of the control. Similarly, if the number is greater than the current number of segments, the new segments are added on the right. This value must be between 0 and 2049.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the selection state of the specified segment.

    Declaration

    Swift

    func setSelected(_ flag: Bool, forSegment segment: Int)

    Objective-C

    - (void)setSelected:(BOOL)flag forSegment:(NSInteger)segment

    Parameters

    flag

    YEStrue if you want to select the segment; otherwise, NOfalse.

    segment

    The index of the segment whose selection state you want to set. This method raises an NSRangeException if the index is out of bounds.

    Discussion

    If the receiver allows only a single selection, this method deselects any other selected segments.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Selects the segment with the specified tag.

    Declaration

    Swift

    func selectSegmentWithTag(_ tag: Int) -> Bool

    Objective-C

    - (BOOL)selectSegmentWithTag:(NSInteger)tag

    Parameters

    tag

    The tag associated with the desired segment.

    Return Value

    YEStrue if the segment was selected successfully; otherwise, NOfalse.

    Discussion

    Typically, you use Interface Builder to specify the tag for each segment. You may also set this value programmatically using the setTag:forSegment: method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Selects the next segment.

    Declaration

    Swift

    func makeNextSegmentKey()

    Objective-C

    - (void)makeNextSegmentKey

    Discussion

    The next segment is the one to the right of the currently selected segment. For the last segment, the selection wraps back to the beginning of the control.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Selects the previous segment.

    Declaration

    Swift

    func makePreviousSegmentKey()

    Objective-C

    - (void)makePreviousSegmentKey

    Discussion

    The previous segment is the one to the left of the currently selected segment. For the first segment, the selection wraps around to the last segment of the control.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • The index of the selected segment of the receiver, or -1 if no segment is selected.

    Declaration

    Swift

    var selectedSegment: Int

    Objective-C

    @property NSInteger selectedSegment

    Discussion

    This property contains the zero-based index of the segment. If the receiver allows multiple selections, the value of this property is the index of the most recently selected segment.

    If you specify an index that is out of bounds, an NSRangeException is raised.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns a Boolean value indicating whether the specified segment is selected,

    Declaration

    Swift

    func isSelectedForSegment(_ segment: Int) -> Bool

    Objective-C

    - (BOOL)isSelectedForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose selection state you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    YEStrue if the segment is selected; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the label for the specified segment.

    Declaration

    Swift

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

    Objective-C

    - (void)setLabel:(NSString *)label forSegment:(NSInteger)segment

    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 NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the label of the specified segment.

    Declaration

    Swift

    func labelForSegment(_ segment: Int) -> String?

    Objective-C

    - (NSString *)labelForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose label you want to get. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the image for the specified segment.

    Declaration

    Swift

    func setImage(_ image: NSImage?, forSegment segment: Int)

    Objective-C

    - (void)setImage:(NSImage *)image forSegment:(NSInteger)segment

    Parameters

    image

    The image to apply to the segment or nil if you want to clear the existing image. Images are not scaled to fit inside a segment. If the image is larger than the available space, it is clipped.

    segment

    The index of the segment whose image you want to set. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the image associated with the specified segment.

    Declaration

    Swift

    func imageForSegment(_ segment: Int) -> NSImage?

    Objective-C

    - (NSImage *)imageForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose image you want to get. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the image scaling mode for the specified segment.

    Declaration

    Swift

    func setImageScaling(_ scaling: NSImageScaling, forSegment segment: Int)

    Objective-C

    - (void)setImageScaling:(NSImageScaling)scaling forSegment:(NSInteger)segment

    Parameters

    scaling

    The scaling mode to assign to the specified segment. For the possible values see Segmented Control Visual Styles.

    segment

    The index of the segment whose image scaling mode you want to set. This method raises an NSRangeException if the index is out of bounds.

    Discussion

    The image scaling mode for a segment affects how the image inside the corresponding cell is positioned and resized when the cell itself grows or shrinks. The image scaling mode does not itself cause the cell to change size in any way. If a cell does not contain an image, the scaling mode has no effect.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the image scaling mode associated with the specified segment.

    Declaration

    Swift

    func imageScalingForSegment(_ segment: Int) -> NSImageScaling

    Objective-C

    - (NSImageScaling)imageScalingForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose image scaling mode you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    The scaling mode in use for the specified segment. For the possible values see Segmented Control Visual Styles. If no value has been explicitly set NSImageScaleProportionallyDown is returned.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the width of the specified segment.

    Declaration

    Swift

    func setWidth(_ width: CGFloat, forSegment segment: Int)

    Objective-C

    - (void)setWidth:(CGFloat)width forSegment:(NSInteger)segment

    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 NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the width of the specified segment.

    Declaration

    Swift

    func widthForSegment(_ segment: Int) -> CGFloat

    Objective-C

    - (CGFloat)widthForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose width you want to get. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the enabled state of the specified segment

    Declaration

    Swift

    func setEnabled(_ flag: Bool, forSegment segment: Int)

    Objective-C

    - (void)setEnabled:(BOOL)flag forSegment:(NSInteger)segment

    Parameters

    flag

    YEStrue to enable the segment; otherwise, NOfalse to disable it.

    segment

    The index of the segment you want to enable or disable. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns a Boolean value indicating whether the specified segment is enabled.

    Declaration

    Swift

    func isEnabledForSegment(_ segment: Int) -> Bool

    Objective-C

    - (BOOL)isEnabledForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose enabled state you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    YEStrue if the segment is enabled; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the menu for the specified segment.

    Declaration

    Swift

    func setMenu(_ menu: NSMenu?, forSegment segment: Int)

    Objective-C

    - (void)setMenu:(NSMenu *)menu forSegment:(NSInteger)segment

    Parameters

    menu

    The menu you want to add to the segment or nil to clear the current menu. This menu is displayed when the user clicks and holds the mouse button while the mouse is over the segment.

    segment

    The index of the segment whose menu you want to set. This method raises an NSRangeException if the index is out of bounds.

    Discussion

    Adding a menu to a segment allows that segment to be used as a pop-up button.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the menu for the specified segment.

    Declaration

    Swift

    func menuForSegment(_ segment: Int) -> NSMenu?

    Objective-C

    - (NSMenu *)menuForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose menu you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    The menu associated with the segment; otherwise, nil.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the tool tip for the specified segment.

    Declaration

    Swift

    func setToolTip(_ toolTip: String?, forSegment segment: Int)

    Objective-C

    - (void)setToolTip:(NSString *)toolTip forSegment:(NSInteger)segment

    Parameters

    toolTip

    The text of the tool tip you want to display for the segment.

    segment

    The index of the segment whose tool tip you want to set. This method raises an NSRangeException if the index is out of bounds.

    Discussion

    Tool tips are currently not displayed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the tool tip of the specified segment.

    Declaration

    Swift

    func toolTipForSegment(_ segment: Int) -> String?

    Objective-C

    - (NSString *)toolTipForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose tool tip you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    The text of the tool tip.

    Discussion

    Tool tips are currently not displayed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the tag for the specified segment.

    Declaration

    Swift

    func setTag(_ tag: Int, forSegment segment: Int)

    Objective-C

    - (void)setTag:(NSInteger)tag forSegment:(NSInteger)segment

    Parameters

    tag

    The tag of the segment.

    segment

    The index of the segment whose tool tag you want to set. This method raises an NSRangeException if the index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the tag of the specified segment.

    Declaration

    Swift

    func tagForSegment(_ segment: Int) -> Int

    Objective-C

    - (NSInteger)tagForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose tool tag you want to get. This method raises an NSRangeException if the index is out of bounds.

    Return Value

    The tag of the segment.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

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

    Declaration

    Swift

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

    Objective-C

    - (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView

    Parameters

    segment

    The index of the segment to draw. This method raises an NSRangeException 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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – drawWithFrame:inView: (NSCell)

  • Returns the interior background style for the specified segment.

    Declaration

    Swift

    func interiorBackgroundStyleForSegment(_ segment: Int) -> NSBackgroundStyle

    Objective-C

    - (NSBackgroundStyle)interiorBackgroundStyleForSegment:(NSInteger)segment

    Parameters

    segment

    The index of the segment whose background style you want to get. This method raises an NSRangeException if the index is out of bounds..

    Return Value

    The background style to use for specified segment. See NSBackgroundStyle for possible values.

    Discussion

    The interior background style describes the surface drawn onto in drawInteriorWithFrame:inView:.

    This is both an override point and a useful method to call. In a custom segment cell with a custom bezel you can override this method to describe the surface on a per-segment basis.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • The visual style used to display the receiver.

    Declaration

    Swift

    var segmentStyle: NSSegmentStyle

    Objective-C

    @property NSSegmentStyle segmentStyle

    Discussion

    This property contains an NSSegmentStyle value that specifies the visual display used by the receiver. For possible values, see Segmented Control Visual Styles in NSSegmentedControl Class Reference.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

Data Types

  • An NSSegmentedCell object uses the following constants, which describe the various tracking modes for a cell. You access these values using setTrackingMode: and trackingMode methods of the class.

    Declaration

    Swift

    enum NSSegmentSwitchTracking : UInt { case SelectOne case SelectAny case Momentary case MomentaryAccelerator }

    Objective-C

    typedef enum { NSSegmentSwitchTrackingSelectOne = 0, NSSegmentSwitchTrackingSelectAny = 1, NSSegmentSwitchTrackingMomentary = 2 } NSSegmentSwitchTracking;

    Constants

    • SelectOne

      NSSegmentSwitchTrackingSelectOne

      Only one segment may be selected.

      Available in OS X v10.3 and later.

    • SelectAny

      NSSegmentSwitchTrackingSelectAny

      Any segment can be selected.

      Available in OS X v10.3 and later.

    • Momentary

      NSSegmentSwitchTrackingMomentary

      A segment is selected only when tracking.

      Available in OS X v10.3 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.