| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.3 and later. |
| Companion guide | |
| Declared in | NSSegmentedCell.h |
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.
– setSelectedSegment:
– setSelected:forSegment:
– selectSegmentWithTag:
– makeNextSegmentKey
– makePreviousSegmentKey
– selectedSegment
– isSelectedForSegment:
– setLabel:forSegment:
– labelForSegment:
– setImage:forSegment:
– imageForSegment:
– setImageScaling:forSegment:
– imageScalingForSegment:
– setWidth:forSegment:
– widthForSegment:
– setEnabled:forSegment:
– isEnabledForSegment:
– setMenu:forSegment:
– menuForSegment:
– setToolTip:forSegment:
– toolTipForSegment:
– setTag:forSegment:
– tagForSegment:
Draws the segment in the specified view.
- (void)drawSegment:(NSInteger)segment inFrame:(NSRect)frame withView:(NSView *)controlView
The index of the segment to draw. This method raises an NSRangeException if the index is out of bounds.
The rectangle in which to draw the segment. This rectangle is specified in user space coordinates of the specified view.
The view in which to draw the segment.
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.
– drawWithFrame:inView: (NSCell)NSSegmentedCell.hReturns the image associated with the specified segment.
- (NSImage *)imageForSegment:(NSInteger)segment
The index of the segment whose image you want to get. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hReturns the image scaling mode associated with the specified segment.
- (NSImageScaling)imageScalingForSegment:(NSInteger)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.
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.
NSSegmentedCell.hReturns the interior background style for the specified segment.
- (NSBackgroundStyle)interiorBackgroundStyleForSegment:(NSInteger)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..
The background style to use for specified segment See Background Styles in NSCell for possible values.
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.
NSSegmentedCell.hReturns a Boolean value indicating whether the specified segment is enabled.
- (BOOL)isEnabledForSegment:(NSInteger)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.
YES if the segment is enabled; otherwise, NO.
NSSegmentedCell.hReturns a Boolean value indicating whether the specified segment is selected,
- (BOOL)isSelectedForSegment:(NSInteger)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.
YES if the segment is selected; otherwise, NO.
NSSegmentedCell.hReturns the label of the specified segment.
- (NSString *)labelForSegment:(NSInteger)segment
The index of the segment whose label you want to get. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hSelects the next segment.
- (void)makeNextSegmentKey
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.
NSSegmentedCell.hSelects the previous segment.
- (void)makePreviousSegmentKey
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.
NSSegmentedCell.hReturns the menu for the specified segment.
- (NSMenu *)menuForSegment:(NSInteger)segment
The index of the segment whose menu you want to get. This method raises an NSRangeException if the index is out of bounds.
The menu associated with the segment; otherwise, nil.
NSSegmentedCell.hReturns the number of segments in the receiver.
- (NSInteger)segmentCount
The number of segments in the receiver.
NSSegmentedCell.hReturns the visual style used to display the receiver.
- (NSSegmentStyle)segmentStyle
An NSSegmentStyle value that specifies the visual display used by the receiver. For possible values see “Segmented Control Visual Styles” in NSSegmentedControl Class Reference.
NSSegmentedCell.hReturns the index of the selected segment of the receiver.
- (NSInteger)selectedSegment
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.
NSSegmentedCell.hSelects the segment with the specified tag.
- (BOOL)selectSegmentWithTag:(NSInteger)tag
The tag associated with the desired segment.
Typically, you use Interface Builder to specify the tag for each segment. You may also set this value programmatically using the setTag:forSegment: method.
NSSegmentedCell.hSets the enabled state of the specified segment
- (void)setEnabled:(BOOL)flag forSegment:(NSInteger)segment
YES to enable the segment; otherwise, NO to disable it.
The index of the segment you want to enable or disable. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hSets the image for the specified segment.
- (void)setImage:(NSImage *)image forSegment:(NSInteger)segment
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.
The index of the segment whose image you want to set. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hSets the image scaling mode for the specified segment.
- (void)setImageScaling:(NSImageScaling)scaling forSegment:(NSInteger)segment
The scaling mode to assign to the specified segment. For the possible values see Segmented Control Visual Styles.
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.
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.
NSSegmentedCell.hSets the label for the specified segment.
- (void)setLabel:(NSString *)label forSegment:(NSInteger)segment
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.
The index of the segment whose label you want to set. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hSets the menu for the specified segment.
- (void)setMenu:(NSMenu *)menu forSegment:(NSInteger)segment
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.
The index of the segment whose menu you want to set. This method raises an NSRangeException if the index is out of bounds.
Adding a menu to a segment allows that segment to be used as a pop-up button.
NSSegmentedCell.hSets the number of segments in the receiver.
- (void)setSegmentCount:(NSInteger)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 0 and 2049.
NSSegmentedCell.hSets the visual style used to display the receiver.
- (void)setSegmentStyle:(NSSegmentStyle)segmentStyle
An NSSegmentStyle value 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.
NSSegmentedCell.hSets the selection state of the specified segment.
- (void)setSelected:(BOOL)flag forSegment:(NSInteger)segment
YES if you want to select the segment; otherwise, NO.
The index of the segment whose selection state you want to set. This method raises an NSRangeException if the index is out of bounds.
If the receiver allows only a single selection, this method deselects any other selected segments.
NSSegmentedCell.hSets the selected segment of the receiver.
- (void)setSelectedSegment:(NSInteger)selectedSegment
The zero-based index of the desired segment. This method raises an NSRangeException if the index is out of bounds.
If the receiver allows multiple selections, this method selects the specified segment using setSelected:forSegment:.
NSSegmentedCell.hSets the tag for the specified segment.
- (void)setTag:(NSInteger)tag forSegment:(NSInteger)segment
The tag of the 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.
NSSegmentedCell.hSets the tool tip for the specified segment.
- (void)setToolTip:(NSString *)toolTip forSegment:(NSInteger)segment
The text of the tool tip you want to display for the 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.
Tool tips are currently not displayed.
NSSegmentedCell.hSets the tracking mode for the receiver.
- (void)setTrackingMode:(NSSegmentSwitchTracking)trackingMode
The tracking mode to use for the segments. Possible values for trackingMode are described in NSSegmentSwitchTracking.
NSSegmentedCell.hSets the width of the specified segment.
- (void)setWidth:(CGFloat)width forSegment:(NSInteger)segment
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.
The index of the segment whose width you want to set. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hReturns the tag of the specified segment.
- (NSInteger)tagForSegment:(NSInteger)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.
The tag of the segment.
NSSegmentedCell.hReturns the tool tip of the specified segment.
- (NSString *)toolTipForSegment:(NSInteger)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.
The text of the tool tip.
Tool tips are currently not displayed.
NSSegmentedCell.hReturns the tracking mode of the receiver.
- (NSSegmentSwitchTracking)trackingMode
The tracking mode used for the segments Possible values for trackingMode are described in NSSegmentSwitchTracking.The default value is NSSegmentSwitchTrackingSelectOne.
NSSegmentedCell.hReturns the width of the specified segment.
- (CGFloat)widthForSegment:(NSInteger)segment
The index of the segment whose width you want to get. This method raises an NSRangeException if the index is out of bounds.
NSSegmentedCell.hAn 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;
NSSegmentSwitchTrackingSelectOneOnly one segment may be selected.
Available in Mac OS X v10.3 and later.
Declared in NSSegmentedCell.h.
NSSegmentSwitchTrackingSelectAnyAny segment can be selected.
Available in Mac OS X v10.3 and later.
Declared in NSSegmentedCell.h.
NSSegmentSwitchTrackingMomentaryA segment is selected only when tracking.
Available in Mac OS X v10.3 and later.
Declared in NSSegmentedCell.h.
NSSegmentedCell.hLast updated: 2009-05-06