iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UISegmentedControl Class Reference

Options
Deployment Target:

On This Page
Language:

UISegmentedControl

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.

A UISegmentedControl object is a horizontal control made of multiple segments, each segment functioning as a discrete button. A segmented control affords a compact means to group together a number of controls.

A segmented control can display a title (an NSString object) or an image (UIImage object). The UISegmentedControl object automatically resizes segments to fit proportionally within their superview unless they have a specific width set. When you add and remove segments, you can request that the action be animated with sliding and fading effects.

You register the target-action methods for a segmented control using the UIControlEventValueChanged constant as shown below.

Swift

  • segmentedControl.addTarget(self, action: "action:", forControlEvents: .ValueChanged);

Objective-C

  • [segmentedControl addTarget:self
  • action:@selector(action:)
  • forControlEvents:UIControlEventValueChanged];

How you configure a segmented control can affect its display behavior:

  • If you set a segmented control to have a momentary style, a segment doesn’t show itself as selected (blue background) when the user touches it. The disclosure button is always momentary and doesn’t affect the actual selection.

  • In versions of iOS prior to 3.0, if a segmented control has only two segments, then it behaves like a switch—tapping the currently-selected segment causes the other segment to be selected. On iOS 3.0 and later, tapping the currently-selected segment does not cause the other segment to be selected.

Customizing Appearance

In iOS v5.0 and later, you can customize the appearance of segmented controls using the methods listed in Customizing Appearance. You can customize the appearance of all segmented controls using the appearance proxy (for example, [UISegmentedControl appearance]), or just of a single control.

When customizing appearance, in general, you should specify a value for the normal state of a property to be used by other states which don’t have a custom value set. Similarly, when a property is dependent on the bar metrics (on the iPhone in landscape orientation, bars have a different height from standard), you should make sure you specify a value for UIBarMetricsDefault.

In the case of the segmented control, appearance properties for UIBarMetricsLandscapePhone are only respected for segmented controls in the smaller navigation and toolbars that are used in landscape orientation on the iPhone.

To provide complete customization, you need to provide divider images for different state combinations, using setDividerImage:forLeftSegmentState:rightSegmentState:barMetrics::

Swift

  • // Image between two unselected segments.
  • mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
  • rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
  • // Image between segment selected on the left and unselected on the right.
  • mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Selected,
  • rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
  • // Image between segment selected on the right and unselected on the left.
  • mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
  • rightSegmentState: UIControlState.Selected, barMetrics: UIBarMetrics.Default)

Objective-C

  • // Image between two unselected segments.
  • [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
  • rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
  • // Image between segment selected on the left and unselected on the right.
  • [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateSelected
  • rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
  • // Image between segment selected on the right and unselected on the right.
  • [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
  • rightSegmentState:UIControlStateSelected barMetrics:barMetrics];

For more information about appearance and behavior configuration, see Segmented Controls.

  • Initializes and returns a segmented control with segments having the given titles or images.

    Declaration

    Swift

    init(items items: [AnyObject])

    Objective-C

    - (instancetype)initWithItems:(NSArray *)items

    Parameters

    items

    An array of NSString objects (for segment titles) or UIImage objects (for segment images).

    Return Value

    A UISegmentedControl object or nil if there was a problem in initializing the object.

    Discussion

    The returned segmented control is automatically sized to fit its content within the width of its superview.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the content of a segment to a given image.

    Declaration

    Swift

    func setImage(_ image: UIImage?, forSegmentAtIndex segment: Int)

    Objective-C

    - (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment

    Parameters

    image

    An image object to display in the segment. .

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Discussion

    A segment can only have an image or a title; it can’t have both. There is no default image.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the image for a specific segment

    Declaration

    Swift

    func imageForSegmentAtIndex(_ segment: Int) -> UIImage?

    Objective-C

    - (UIImage *)imageForSegmentAtIndex:(NSUInteger)segment

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Return Value

    Returns the image assigned to the receiver as content. If no image has been set, it returns nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the title of a segment.

    Declaration

    Swift

    func setTitle(_ title: String?, forSegmentAtIndex segment: Int)

    Objective-C

    - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment

    Parameters

    title

    A string to display in the segment as its title.

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Discussion

    A segment can only have an image or a title; it can’t have both. There is no default title.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the title of the specified segment.

    Declaration

    Swift

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

    Objective-C

    - (NSString *)titleForSegmentAtIndex:(NSUInteger)segment

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Return Value

    Returns the string (title) assigned to the receiver as content. If no title has been set, it returns nil.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Inserts a segment at a specified position in the receiver and gives it an image as content.

    Declaration

    Swift

    func insertSegmentWithImage(_ image: UIImage, atIndex segment: Int, animated animated: Bool)

    Objective-C

    - (void)insertSegmentWithImage:(UIImage *)image atIndex:(NSUInteger)segment animated:(BOOL)animated

    Parameters

    image

    An image object to use as the content of the segment.

    segment

    An index number identifying a segment in the control.

    segment must be a number in the range 0 to the number of segments (numberOfSegments) inclusive; values exceeding this upper range are pinned to it.

    The new segment is inserted just before the designated one.

    animated

    YEStrue if the insertion of the new segment should be animated, otherwise NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Inserts a segment at a specific position in the receiver and gives it a title as content.

    Declaration

    Swift

    func insertSegmentWithTitle(_ title: String!, atIndex segment: Int, animated animated: Bool)

    Objective-C

    - (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated

    Parameters

    title

    A string to use as the segment’s title.

    segment

    An index number identifying a segment in the control.

    segment must be a number in the range 0 to the number of segments (numberOfSegments) inclusive; values exceeding this upper range are pinned to it.

    The new segment is inserted just before the designated one.

    animated

    YEStrue if the insertion of the new segment should be animated, otherwise NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the number of segments the receiver has. (read-only)

    Declaration

    Swift

    var numberOfSegments: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSUInteger numberOfSegments

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Removes all segments of the receiver

    Declaration

    Swift

    func removeAllSegments()

    Objective-C

    - (void)removeAllSegments

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Removes the specified segment from the receiver, optionally animating the transition.

    Declaration

    Swift

    func removeSegmentAtIndex(_ segment: Int, animated animated: Bool)

    Objective-C

    - (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    animated

    YEStrue if the removal of the new segment should be animated, otherwise NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The index number identifying the selected segment (that is, the last segment touched).

    Declaration

    Swift

    var selectedSegmentIndex: Int

    Objective-C

    @property(nonatomic) NSInteger selectedSegmentIndex

    Discussion

    The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection. UISegmentedControl ignores this property when the control is in momentary mode. When the user touches a segment to change the selection, the control event UIControlEventValueChanged is generated; if the segmented control is set up to respond to this control event, it sends a action message to its target.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    momentary

  • momentary momentary Property

    A Boolean value that determines whether segments in the receiver show selected state.

    Declaration

    Swift

    var momentary: Bool

    Objective-C

    @property(nonatomic, getter=isMomentary) BOOL momentary

    Discussion

    The default value of this property is NOfalse. If it is set to YEStrue, segments in the control do not show selected state and do not update the value of selectedSegmentIndex after tracking ends.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The style of the segmented control.

    Deprecation Statement

    Segmented controls no longer support multiple styles using this functionality. Use the other appearance modification methods and properties to customize a segmented control.

    Declaration

    Objective-C

    @property(nonatomic) UISegmentedControlStyle segmentedControlStyle

    Discussion

    The default style is UISegmentedControlStylePlain. See UISegmentedControlStyle for descriptions of valid constants.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • Enables the specified segment.

    Declaration

    Swift

    func setEnabled(_ enabled: Bool, forSegmentAtIndex segment: Int)

    Objective-C

    - (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment

    Parameters

    enabled

    YEStrue to enable the specified segment or NOfalse to disable the segment. By default, segments are enabled.

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns whether the indicated segment is enabled.

    Declaration

    Swift

    func isEnabledForSegmentAtIndex(_ segment: Int) -> Bool

    Objective-C

    - (BOOL)isEnabledForSegmentAtIndex:(NSUInteger)segment

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Return Value

    YEStrue if the given segment is enabled and NOfalse if the segment is disabled. By default, segments are enabled.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Adjusts the offset for drawing the content (image or text) of the specified segment.

    Declaration

    Swift

    func setContentOffset(_ offset: CGSize, forSegmentAtIndex segment: Int)

    Objective-C

    - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment

    Parameters

    offset

    The offset (specified as a CGSize type) from the origin of the segment at which to draw the segment’s content. The default offset is (0,0).

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the offset for drawing the content (image or text) of the specified segment.

    Declaration

    Swift

    func contentOffsetForSegmentAtIndex(_ segment: Int) -> CGSize

    Objective-C

    - (CGSize)contentOffsetForSegmentAtIndex:(NSUInteger)segment

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Return Value

    The offset (specified as a CGSize structure) from the origin of the segment at which to draw the segment’s content.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the width of the specified segment of the receiver.

    Declaration

    Swift

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

    Objective-C

    - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment

    Parameters

    width

    A float value specifying the width of the segment. The default value is {0.0}, which tells UISegmentedControl to automatically size the segment.

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the width of the indicated segment of the receiver.

    Declaration

    Swift

    func widthForSegmentAtIndex(_ segment: Int) -> CGFloat

    Objective-C

    - (CGFloat)widthForSegmentAtIndex:(NSUInteger)segment

    Parameters

    segment

    An index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.

    Return Value

    A float value specifying the width of the segment. If the value is {0.0}, UISegmentedControl automatically sizes the segment.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Indicates whether the control attempts to adjust segment widths based on their content widths.

    Declaration

    Swift

    var apportionsSegmentWidthsByContent: Bool

    Objective-C

    @property(nonatomic) BOOL apportionsSegmentWidthsByContent

    Discussion

    If the value of this property is YEStrue, for segments whose width value is 0, the control attempts to adjust segment widths based on their content widths.

    The default is NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • tintColor tintColor Property

    The tint color to apply to key elements in the segmented control.

    Declaration

    Swift

    var tintColor: UIColor!

    Objective-C

    @property(nonatomic, retain) UIColor *tintColor

    Discussion

    In iOS v7.0, all subclasses of UIView derive their behavior for tintColor from the base class. See the discussion of tintColor at the UIView level for more information.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the background image for a given state and bar metrics.

    Declaration

    Swift

    func backgroundImageForState(_ state: UIControlState, barMetrics barMetrics: UIBarMetrics) -> UIImage?

    Objective-C

    - (UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics

    Parameters

    state

    A control state.

    barMetrics

    Bar metrics.

    Return Value

    The background image for state and barMetrics.

    Discussion

    For more details, see setBackgroundImage:forState:barMetrics:.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Sets the background image for a given state and bar metrics.

    Declaration

    Swift

    func setBackgroundImage(_ backgroundImage: UIImage?, forState state: UIControlState, barMetrics barMetrics: UIBarMetrics)

    Objective-C

    - (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics

    Parameters

    backgroundImage

    The background image to use for state and barMetrics.

    state

    A control state.

    barMetrics

    Bar metrics.

    Discussion

    If backgroundImage is an image returned from resizableImageWithCapInsets:, the cap widths are calculated from that information.

    If backgroundImage is not an image returned from resizableImageWithCapInsets:, the cap width is calculated by subtracting one from the image's width then dividing by 2. The cap widths are used as the margins for text placement. To adjust the margin, use the margin adjustment methods.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Returns the positioning offset for a given segment and bar metrics.

    Declaration

    Swift

    func contentPositionAdjustmentForSegmentType(_ leftCenterRightOrAlone: UISegmentedControlSegment, barMetrics barMetrics: UIBarMetrics) -> UIOffset

    Objective-C

    - (UIOffset)contentPositionAdjustmentForSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics

    Parameters

    leftCenterRightOrAlone

    An identifier for a segment.

    barMetrics

    Bar metrics.

    Return Value

    The content positioning offset for the segment identified by leftCenterRightOrAlone and barMetrics.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Returns the content positioning offset for a given segment and bar metrics.

    Declaration

    Swift

    func setContentPositionAdjustment(_ adjustment: UIOffset, forSegmentType leftCenterRightOrAlone: UISegmentedControlSegment, barMetrics barMetrics: UIBarMetrics)

    Objective-C

    - (void)setContentPositionAdjustment:(UIOffset)adjustment forSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics

    Parameters

    adjustment

    The positioning offset for the segment identified by leftCenterRightOrAlone and barMetrics.

    leftCenterRightOrAlone

    An identifier for a segment type.

    barMetrics

    Bar metrics.

    Discussion

    You use this method to adjust the position of a title or image within the given segment of a segmented control.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Returns the divider image used for a given combination of left and right segment states and bar metrics.

    Declaration

    Swift

    func dividerImageForLeftSegmentState(_ leftState: UIControlState, rightSegmentState rightState: UIControlState, barMetrics barMetrics: UIBarMetrics) -> UIImage?

    Objective-C

    - (UIImage *)dividerImageForLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics

    Parameters

    leftState

    The state of the left segment.

    rightState

    The state of the right segment.

    barMetrics

    Bar metrics.

    Return Value

    The divider image used for the given combination of left and right segment states and bar metrics

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Sets the divider image used for a given combination of left and right segment states and bar metrics.

    Declaration

    Swift

    func setDividerImage(_ dividerImage: UIImage?, forLeftSegmentState leftState: UIControlState, rightSegmentState rightState: UIControlState, barMetrics barMetrics: UIBarMetrics)

    Objective-C

    - (void)setDividerImage:(UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics

    Parameters

    dividerImage

    The divider image to use.

    leftState

    The state of the left segment.

    rightState

    The state of the right segment.

    barMetrics

    Bar metrics.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Returns the text attributes of the title for a given control state.

    Declaration

    Swift

    func titleTextAttributesForState(_ state: UIControlState) -> [NSObject : AnyObject]!

    Objective-C

    - (NSDictionary *)titleTextAttributesForState:(UIControlState)state

    Parameters

    state

    A control state.

    Return Value

    The text attributes of the title for state.

    Discussion

    For more details, see setTitleTextAttributes:forState:

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Sets the text attributes of the title for a given control state.

    Declaration

    Swift

    func setTitleTextAttributes(_ attributes: [NSObject : AnyObject]?, forState state: UIControlState)

    Objective-C

    - (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state

    Parameters

    attributes

    The text attributes of the title for state.

    state

    A control state.

    Discussion

    The attributes dictionary can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the keys in NSString UIKit Additions Reference.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The styles of the segmented control.

    Use tintColor instead.

    Declaration

    Objective-C

    typedef enum { UISegmentedControlStylePlain, UISegmentedControlStyleBordered, UISegmentedControlStyleBar, UISegmentedControlStyleBezeled, } UISegmentedControlStyle;

    Constants

    • UISegmentedControlStylePlain

      UISegmentedControlStylePlain

      The large plain style for segmented controls. This style is the default.

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    • UISegmentedControlStyleBordered

      UISegmentedControlStyleBordered

      The large bordered style for segmented controls.

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    • UISegmentedControlStyleBar

      UISegmentedControlStyleBar

      The small toolbar style for segmented controls. Segmented controls in this style can have a tint color (see tintColor).

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    • UISegmentedControlStyleBezeled

      UISegmentedControlStyleBezeled

      The large bezeled style for segmented controls. Segmented controls in this style can have a tint color (see tintColor).

      This control style was deprecated in iOS 5.1 and should not be used.

      Available in iOS 2.0 and later.

      Deprecated in iOS 7.0.

    Discussion

    You use these constants as values for the segmentedControlStyle property.

    Import Statement

    Objective-C

    @import UIKit;

    Availability

    Available in iOS 2.0 and later.

    Deprecated in iOS 7.0.

  • A constant for indicating that no segment is selected.

    Declaration

    Swift

    var UISegmentedControlNoSegment: Int { get }

    Objective-C

    enum { UISegmentedControlNoSegment = -1 };

    Constants

    • UISegmentedControlNoSegment

      UISegmentedControlNoSegment

      A segment index value indicating that there is no selected segment. See selectedSegmentIndex for further information.

      Available in iOS 2.0 and later.

  • Constants for specifying a segment in a control

    Declaration

    Swift

    enum UISegmentedControlSegment : Int { case Any case Left case Center case Right case Alone }

    Objective-C

    typedef enum { UISegmentedControlSegmentAny = 0, UISegmentedControlSegmentLeft = 1, UISegmentedControlSegmentCenter = 2, UISegmentedControlSegmentRight = 3, UISegmentedControlSegmentAlone = 4, } UISegmentedControlSegment;

    Constants

    • Any

      UISegmentedControlSegmentAny

      Specifies any segment.

      Available in iOS 5.0 and later.

    • Left

      UISegmentedControlSegmentLeft

      The capped, leftmost segment.

      Only applies when numSegments > 1.

      Available in iOS 5.0 and later.

    • Center

      UISegmentedControlSegmentCenter

      Any segment between the left and rightmost segments.

      Only applies when numSegments > 2.

      Available in iOS 5.0 and later.

    • Right

      UISegmentedControlSegmentRight

      The capped,rightmost segment. .

      Only applies when numSegments > 1.

      Available in iOS 5.0 and later.

    • Alone

      UISegmentedControlSegmentAlone

      The standalone segment, capped on both ends.

      Only applies when numSegments = 1.

      Available in iOS 5.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.