NSSegmentedCell Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.3 and later. |
| Companion guide | |
| Declared in | NSSegmentedCell.h |
Overview
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.
Tasks
Specifying the Number of Segments
Specifying the Selected Segment
-
– setSelectedSegment: -
– setSelected:forSegment: -
– selectSegmentWithTag: -
– makeNextSegmentKey -
– makePreviousSegmentKey -
– selectedSegment -
– isSelectedForSegment:
Specifying the Tracking Mode
Configuring Individual Segments
-
– setLabel:forSegment: -
– labelForSegment: -
– setImage:forSegment: -
– imageForSegment: -
– setImageScaling:forSegment: -
– imageScalingForSegment: -
– setWidth:forSegment: -
– widthForSegment: -
– setEnabled:forSegment: -
– isEnabledForSegment: -
– setMenu:forSegment: -
– menuForSegment: -
– setToolTip:forSegment: -
– toolTipForSegment: -
– setTag:forSegment: -
– tagForSegment:
Drawing Custom Content
Specifying Segment Visual Styles
Instance Methods
drawSegment:inFrame:withView:
Draws the segment in the specified view.
Parameters
- segment
The index of the segment to draw. This method raises an
NSRangeExceptionif the index is out of bounds.- frame
The rectangle in which to draw the segment. This rectangle is specified in user space coordinates of the specified view.
- controlView
The view in which to draw 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.
Availability
- Available in OS X v10.3 and later.
See Also
-
– drawWithFrame:inView:(NSCell)
Declared In
NSSegmentedCell.himageForSegment:
Returns the image associated with the specified segment.
Parameters
- segment
The index of the segment whose image you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.himageScalingForSegment:
Returns the image scaling mode associated with the specified segment.
Parameters
- segment
The index of the segment whose image scaling mode you want to get. This method raises an
NSRangeExceptionif 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.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSSegmentedCell.hinteriorBackgroundStyleForSegment:
Returns the interior background style for the specified segment.
Parameters
- segment
The index of the segment whose background style you want to get. This method raises an
NSRangeExceptionif the index is out of bounds..
Return Value
The background style to use for specified segment See Background Styles in NSCell 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.
Availability
- Available in OS X v10.5 and later.
Declared In
NSSegmentedCell.hisEnabledForSegment:
Returns a Boolean value indicating whether the specified segment is enabled.
Parameters
- segment
The index of the segment whose enabled state you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Return Value
YES if the segment is enabled; otherwise, NO.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hisSelectedForSegment:
Returns a Boolean value indicating whether the specified segment is selected,
Parameters
- segment
The index of the segment whose selection state you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Return Value
YES if the segment is selected; otherwise, NO.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hlabelForSegment:
Returns the label of the specified segment.
Parameters
- segment
The index of the segment whose label you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hmakeNextSegmentKey
Selects the next segment.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hmakePreviousSegmentKey
Selects the previous segment.
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.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hmenuForSegment:
Returns the menu for the specified segment.
Parameters
- segment
The index of the segment whose menu you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Return Value
The menu associated with the segment; otherwise, nil.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsegmentCount
Returns the number of segments in the receiver.
Return Value
The number of segments in the receiver.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsegmentStyle
Returns the visual style used to display the receiver.
Return Value
An NSSegmentStyle value that specifies the visual display used by the receiver. For possible values see “Segmented Control Visual Styles” in NSSegmentedControl Class Reference.
Availability
- Available in OS X v10.5 and later.
Declared In
NSSegmentedCell.hselectedSegment
Returns the index of the selected segment of the receiver.
Return Value
The index of the currently selected segment, or -1 if no segment is selected. If the receiver allows multiple selections, this method returns the most recently selected segment.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hselectSegmentWithTag:
Selects the segment with the specified tag.
Parameters
- tag
The tag associated with the desired segment.
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.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSSegmentedCell.hsetEnabled:forSegment:
Sets the enabled state of the specified segment
Parameters
- flag
YESto enable the segment; otherwise,NOto disable it.- segment
The index of the segment you want to enable or disable. This method raises an
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetImage:forSegment:
Sets the image for the specified segment.
Parameters
- image
The image to apply to the segment or
nilif 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
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetImageScaling:forSegment:
Sets the image scaling mode for the specified 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
NSRangeExceptionif 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.
Availability
- Available in OS X v10.5 and later.
See Also
Declared In
NSSegmentedCell.hsetLabel:forSegment:
Sets the label for the specified 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
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetMenu:forSegment:
Sets the menu for the specified segment.
Parameters
- menu
The menu you want to add to the segment or
nilto 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
NSRangeExceptionif the index is out of bounds.
Discussion
Adding a menu to a segment allows that segment to be used as a pop-up button.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetSegmentCount:
Sets the number of segments in the receiver.
Parameters
- count
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
0and2049.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetSegmentStyle:
Sets the visual style used to display the receiver.
Parameters
- segmentStyle
An
NSSegmentStylevalue that specifies the visual display used by the receiver. For possible values see “Segmented Control Visual Styles” in NSSegmentedControl Class Reference in NSSegmentedControl Class Reference.
Availability
- Available in OS X v10.5 and later.
Declared In
NSSegmentedCell.hsetSelected:forSegment:
Sets the selection state of the specified segment.
Parameters
- flag
YESif you want to select the segment; otherwise,NO.- segment
The index of the segment whose selection state you want to set. This method raises an
NSRangeExceptionif the index is out of bounds.
Discussion
If the receiver allows only a single selection, this method deselects any other selected segments.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetSelectedSegment:
Sets the selected segment of the receiver.
Parameters
- selectedSegment
The zero-based index of the desired segment. This method raises an
NSRangeExceptionif the index is out of bounds.
Discussion
If the receiver allows multiple selections, this method selects the specified segment using setSelected:forSegment:.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetTag:forSegment:
Sets the tag for the specified 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
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetToolTip:forSegment:
Sets the tool tip for the specified 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
NSRangeExceptionif the index is out of bounds.
Discussion
Tool tips are currently not displayed.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetTrackingMode:
Sets the tracking mode for the receiver.
Parameters
- trackingMode
The tracking mode to use for the segments. Possible values for trackingMode are described in
NSSegmentSwitchTracking.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hsetWidth:forSegment:
Sets the width of the specified segment.
Parameters
- width
The width of the segment, measured in points. Specify the value
0if 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
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.htagForSegment:
Returns the tag of the specified segment.
Parameters
- segment
The index of the segment whose tool tag you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Return Value
The tag of the segment.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.htoolTipForSegment:
Returns the tool tip of the specified segment.
Parameters
- segment
The index of the segment whose tool tip you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Return Value
The text of the tool tip.
Discussion
Tool tips are currently not displayed.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.htrackingMode
Returns the tracking mode of the receiver.
Return Value
The tracking mode used for the segments Possible values for trackingMode are described in NSSegmentSwitchTracking.The default value is NSSegmentSwitchTrackingSelectOne.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hwidthForSegment:
Returns the width of the specified segment.
Parameters
- segment
The index of the segment whose width you want to get. This method raises an
NSRangeExceptionif the index is out of bounds.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSegmentedCell.hConstants
NSSegmentSwitchTracking
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.
typedef enum {
NSSegmentSwitchTrackingSelectOne = 0,
NSSegmentSwitchTrackingSelectAny = 1,
NSSegmentSwitchTrackingMomentary = 2
} NSSegmentSwitchTracking;
Constants
NSSegmentSwitchTrackingSelectOneOnly one segment may be selected.
Available in OS X v10.3 and later.
Declared in
NSSegmentedCell.h.NSSegmentSwitchTrackingSelectAnyAny segment can be selected.
Available in OS X v10.3 and later.
Declared in
NSSegmentedCell.h.NSSegmentSwitchTrackingMomentaryA segment is selected only when tracking.
Available in OS X v10.3 and later.
Declared in
NSSegmentedCell.h.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSegmentedCell.h© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-05-06)