Class: UISegmentedControl

Inherits:
UIControl show all

Overview

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.

Instance Attribute Summary (collapse)

Attributes inherited from UIControl

#contentHorizontalAlignment, #contentVerticalAlignment, #enabled, #highlighted, #selected, #state, #touchInside, #tracking

Attributes inherited from UIView

#alpha, #autoresizesSubviews, #autoresizingMask, #backgroundColor, #bounds, #center, #clearsContextBeforeDrawing, #clipsToBounds, #contentMode, #contentScaleFactor, #exclusiveTouch, #frame, #gestureRecognizers, #hidden, #layer, #multipleTouchEnabled, #opaque, #restorationIdentifier, #subviews, #superview, #tag, #transform, #userInteractionEnabled, #window

Attributes inherited from UIResponder

#inputAccessoryView, #inputView, #undoManager

Instance Method Summary (collapse)

Methods inherited from UIControl

#actionsForTarget:forControlEvent:, #addTarget:action:forControlEvents:, #allControlEvents, #allTargets, #beginTrackingWithTouch:withEvent:, #cancelTrackingWithEvent:, #continueTrackingWithTouch:withEvent:, #endTrackingWithTouch:withEvent:, #removeTarget:action:forControlEvents:, #sendAction:to:forEvent:, #sendActionsForControlEvents:

Methods inherited from UIView

#addConstraint:, #addConstraints:, #addGestureRecognizer:, #addSubview:, #alignmentRectForFrame:, #alignmentRectInsets, animateWithDuration:animations:, animateWithDuration:animations:completion:, animateWithDuration:delay:options:animations:completion:, areAnimationsEnabled, beginAnimations:context:, #bringSubviewToFront:, commitAnimations, #constraints, #constraintsAffectingLayoutForAxis:, #contentCompressionResistancePriorityForAxis:, #contentHuggingPriorityForAxis:, #convertPoint:fromView:, #convertPoint:toView:, #convertRect:fromView:, #convertRect:toView:, #decodeRestorableStateWithCoder:, #didAddSubview:, #didMoveToSuperview, #didMoveToWindow, #drawRect:, #drawRect:forViewPrintFormatter:, #encodeRestorableStateWithCoder:, #endEditing:, #exchangeSubviewAtIndex:withSubviewAtIndex:, #exerciseAmbiguityInLayout, #frameForAlignmentRect:, #gestureRecognizerShouldBegin:, #hasAmbiguousLayout, #hitTest:withEvent:, #initWithFrame:, #insertSubview:aboveSubview:, #insertSubview:atIndex:, #insertSubview:belowSubview:, #intrinsicContentSize, #invalidateIntrinsicContentSize, #isDescendantOfView:, layerClass, #layoutIfNeeded, #layoutSubviews, #needsUpdateConstraints, #pointInside:withEvent:, #removeConstraint:, #removeConstraints:, #removeFromSuperview, #removeGestureRecognizer:, requiresConstraintBasedLayout, #sendSubviewToBack:, setAnimationBeginsFromCurrentState:, setAnimationCurve:, setAnimationDelay:, setAnimationDelegate:, setAnimationDidStopSelector:, setAnimationDuration:, setAnimationRepeatAutoreverses:, setAnimationRepeatCount:, setAnimationStartDate:, setAnimationTransition:forView:cache:, setAnimationWillStartSelector:, setAnimationsEnabled:, #setContentCompressionResistancePriority:forAxis:, #setContentHuggingPriority:forAxis:, #setNeedsDisplay, #setNeedsDisplayInRect:, #setNeedsLayout, #setNeedsUpdateConstraints, #setTranslatesAutoresizingMaskIntoConstraints:, #sizeThatFits:, #sizeToFit, #systemLayoutSizeFittingSize:, transitionFromView:toView:duration:options:completion:, transitionWithView:duration:options:animations:completion:, #translatesAutoresizingMaskIntoConstraints, #updateConstraints, #updateConstraintsIfNeeded, #viewForBaselineLayout, #viewPrintFormatter, #viewWithTag:, #willMoveToSuperview:, #willMoveToWindow:, #willRemoveSubview:

Methods inherited from UIResponder

#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Boolean) apportionsSegmentWidthsByContent

Indicates whether the control attempts to adjust segment widths based on their content widths. If the value of this property is YES, for segments whose width value is 0, the control attempts to adjust segment widths based on their content widths. The default is NO.

Returns:

  • (Boolean)

- (Boolean) momentary

A Boolean value that determines whether segments in the receiver show selected state. The default value of this property is NO. If it is set to YES, segments in the control do not show selected state and do not update the value of selectedSegmentIndex after tracking ends.

Returns:

  • (Boolean)

- (Integer) numberOfSegments (readonly)

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

Returns:

- (UISegmentedControlStyle) segmentedControlStyle

The style of the segmented control. The default style is UISegmentedControlStylePlain. See “UISegmentedControlStyle” for descriptions of valid constants.

- (Integer) selectedSegmentIndex

The index number identifying the selected segment (that is, the last segment touched). 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.

Returns:

- (UIColor) tintColor

The tint color of the segmented control. The default value of this property is nil (no color). UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.

Returns:

Instance Method Details

- (UIImage) backgroundImageForState(state, barMetrics:barMetrics)

Returns the background image for a given state and bar metrics. For more details, see setBackgroundImage:forState:barMetrics:.

Parameters:

  • state (UIControlState)

    A control state.

  • barMetrics (UIBarMetrics)

    Bar metrics.

Returns:

  • (UIImage)

    The background image for state and barMetrics.

- (CGSize) contentOffsetForSegmentAtIndex(segment)

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

Parameters:

  • segment (Integer)

    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.

Returns:

  • (CGSize)

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

- (UIOffset) contentPositionAdjustmentForSegmentType(leftCenterRightOrAlone, barMetrics:barMetrics)

Returns the positioning offset for a given segment and bar metrics. For more details, see setContentPositionAdjustment:forSegmentType:barMetrics:.

Parameters:

Returns:

  • (UIOffset)

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

- (UIImage) dividerImageForLeftSegmentState(leftState, rightSegmentState:rightState, barMetrics:barMetrics)

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

Parameters:

  • leftState (UIControlState)

    The state of the left segment.

  • rightState (UIControlState)

    The state of the right segment.

  • barMetrics (UIBarMetrics)

    Bar metrics.

Returns:

  • (UIImage)

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

- (UIImage) imageForSegmentAtIndex(segment.)

Returns the image for a specific segment

Parameters:

  • segment (Integer)

    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.

Returns:

  • (UIImage)

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

- (Object) initWithItems(items)

Initializes and returns a segmented control with segments having the given titles or images. The returned segmented control is automatically sized to fit its content within the width of its superview.

Parameters:

  • items (Array)

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

Returns:

- (Object) insertSegmentWithImage(image, atIndex:segment, animated:animated)

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

Parameters:

  • image (UIImage)

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

  • segment (Integer)

    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 (Boolean)

    YES if the insertion of the new segment should be animated, otherwise NO.

Returns:

- (Object) insertSegmentWithTitle(title, atIndex:segment, animated:animated)

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

Parameters:

  • title (String)

    A string to use as the segment’s title.

  • segment (Integer)

    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 (Boolean)

    YES if the insertion of the new segment should be animated, otherwise NO.

Returns:

- (Boolean) isEnabledForSegmentAtIndex(segment)

Returns whether the indicated segment is enabled.

Parameters:

  • segment (Integer)

    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.

Returns:

  • (Boolean)

    YES if the given segment is enabled and NO if the segment is disabled. By default, segments are enabled.

- (Object) removeAllSegments

Removes all segments of the receiver

Returns:

- (Object) removeSegmentAtIndex(segment, animated:animated)

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

Parameters:

  • segment (Integer)

    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 (Boolean)

    YES if the removal of the new segment should be animated, otherwise NO.

Returns:

- (Object) setBackgroundImage(backgroundImage, forState:state, barMetrics:barMetrics)

Sets the background image for a given state and bar metrics. 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.DiscussionFor more details, see backgroundImageForState:barMetrics:.

Parameters:

  • backgroundImage (UIImage)

    The background image to use for state and barMetrics.

  • state (UIControlState)

    A control state.

  • barMetrics (UIBarMetrics)

    Bar metrics.

Returns:

- (Object) setContentOffset(offset, forSegmentAtIndex:segment)

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

Parameters:

  • offset (CGSize)

    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 (Integer)

    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.

Returns:

- (Object) setContentPositionAdjustment(adjustment, forSegmentType:leftCenterRightOrAlone, barMetrics:barMetrics)

Returns the content positioning offset for a given segment and bar metrics. You use this method to adjust the position of a title or image within the given segment of a segmented control.

Parameters:

  • adjustment (UIOffset)

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

  • leftCenterRightOrAlone (UISegmentedControlSegment)

    An identifier for a segment type.

  • barMetrics (UIBarMetrics)

    Bar metrics.

Returns:

- (Object) setDividerImage(dividerImage, forLeftSegmentState:leftState, rightSegmentState:rightState, barMetrics:barMetrics)

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

Parameters:

  • dividerImage (UIImage)

    The divider image to use.

  • leftState (UIControlState)

    The state of the left segment.

  • rightState (UIControlState)

    The state of the right segment.

  • barMetrics (UIBarMetrics)

    Bar metrics.

Returns:

- (Object) setEnabled(enabled, forSegmentAtIndex:segment)

Enables the specified segment.

Parameters:

  • enabled (Boolean)

    YES to enable the specified segment or NO to disable the segment. By default, segments are enabled.

  • segment (Integer)

    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.

Returns:

- (Object) setImage(image, forSegmentAtIndex:segment)

Sets the content of a segment to a given image. A segment can only have an image or a title; it can’t have both. There is no default image.

Parameters:

  • image (UIImage)

    An image object to display in the segment. .

  • segment (Integer)

    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.

Returns:

- (Object) setTitle(title, forSegmentAtIndex:segment)

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

Parameters:

  • title (String)

    A string to display in the segment as its title.

  • segment (Integer)

    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.

Returns:

- (Object) setTitleTextAttributes(attributes, forState:state)

Sets the text attributes of the title for a given control state. 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.

Parameters:

  • attributes (Hash)

    The text attributes of the title for state.

  • state (UIControlState)

    A control state.

Returns:

- (Object) setWidth(width, forSegmentAtIndex:segment)

Sets the width of the specified segment of the receiver.

Parameters:

  • width (Float)

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

  • segment (Integer)

    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.

Returns:

- (String) titleForSegmentAtIndex(segment)

Returns the title of the specified segment.

Parameters:

  • segment (Integer)

    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.

Returns:

  • (String)

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

- (Hash) titleTextAttributesForState(state)

Returns the text attributes of the title for a given control state. For more details, see setTitleTextAttributes:forState:

Parameters:

  • state (UIControlState)

    A control state.

Returns:

  • (Hash)

    The text attributes of the title for state.

- (Float) widthForSegmentAtIndex(segment)

Returns the width of the indicated segment of the receiver.

Parameters:

  • segment (Integer)

    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.

Returns: