Class: UISegmentedControl
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)
-
- apportionsSegmentWidthsByContent
Indicates whether the control attempts to adjust segment widths based on their content widths.
-
- momentary
A Boolean value that determines whether segments in the receiver show selected state.
-
- numberOfSegments
readonly
Returns the number of segments the receiver has.
-
- segmentedControlStyle
The style of the segmented control.
-
- selectedSegmentIndex
The index number identifying the selected segment (that is, the last segment touched).
-
- tintColor
The tint color of the segmented control.
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)
-
- backgroundImageForState:barMetrics:
Returns the background image for a given state and bar metrics.
-
- contentOffsetForSegmentAtIndex:
Returns the offset for drawing the content (image or text) of the specified segment.
-
- contentPositionAdjustmentForSegmentType:barMetrics:
Returns the positioning offset for a given segment and bar metrics.
-
- dividerImageForLeftSegmentState:rightSegmentState:barMetrics:
Returns the divider image used for a given combination of left and right segment states and bar metrics.
-
- imageForSegmentAtIndex:
Returns the image for a specific segment.
-
- initWithItems:
Initializes and returns a segmented control with segments having the given titles or images.
-
- insertSegmentWithImage:atIndex:animated:
Inserts a segment at a specified position in the receiver and gives it an image as content.
-
- insertSegmentWithTitle:atIndex:animated:
Inserts a segment at a specific position in the receiver and gives it a title as content.
-
- isEnabledForSegmentAtIndex:
Returns whether the indicated segment is enabled.
-
- removeAllSegments
Removes all segments of the receiver.
-
- removeSegmentAtIndex:animated:
Removes the specified segment from the receiver, optionally animating the transition.
-
- setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
-
- setContentOffset:forSegmentAtIndex:
Adjusts the offset for drawing the content (image or text) of the specified segment.
-
- setContentPositionAdjustment:forSegmentType:barMetrics:
Returns the content positioning offset for a given segment and bar metrics.
-
- setDividerImage:forLeftSegmentState:rightSegmentState:barMetrics:
Sets the divider image used for a given combination of left and right segment states and bar metrics.
-
- setEnabled:forSegmentAtIndex:
Enables the specified segment.
-
- setImage:forSegmentAtIndex:
Sets the content of a segment to a given image.
-
- setTitle:forSegmentAtIndex:
Sets the title of a segment.
-
- setTitleTextAttributes:forState:
Sets the text attributes of the title for a given control state.
-
- setWidth:forSegmentAtIndex:
Sets the width of the specified segment of the receiver.
-
- titleForSegmentAtIndex:
Returns the title of the specified segment.
-
- titleTextAttributesForState:
Returns the text attributes of the title for a given control state.
-
- widthForSegmentAtIndex:
Returns the width of the indicated segment of the receiver.
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.
- (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.
- (Integer) numberOfSegments (readonly)
Returns the number of segments the receiver has. (read-only)
- (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.
- (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.
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:.
- (CGSize) contentOffsetForSegmentAtIndex(segment)
Returns the offset for drawing the content (image or text) of the specified segment.
- (UIOffset) contentPositionAdjustmentForSegmentType(leftCenterRightOrAlone, barMetrics:barMetrics)
Returns the positioning offset for a given segment and bar metrics. For more details, see setContentPositionAdjustment:forSegmentType: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.
- (UIImage) imageForSegmentAtIndex(segment.)
Returns the image for a specific segment
- (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.
- (Object) insertSegmentWithImage(image, atIndex:segment, animated:animated)
Inserts a segment at a specified position in the receiver and gives it an image as content.
- (Object) insertSegmentWithTitle(title, atIndex:segment, animated:animated)
Inserts a segment at a specific position in the receiver and gives it a title as content.
- (Boolean) isEnabledForSegmentAtIndex(segment)
Returns whether the indicated segment is enabled.
- (Object) removeAllSegments
Removes all segments of the receiver
- (Object) removeSegmentAtIndex(segment, animated:animated)
Removes the specified segment from the receiver, optionally animating the transition.
- (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:.
- (Object) setContentOffset(offset, forSegmentAtIndex:segment)
Adjusts the offset for drawing the content (image or text) of the specified segment.
- (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.
- (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.
- (Object) setEnabled(enabled, forSegmentAtIndex:segment)
Enables the specified segment.
- (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.
- (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.
- (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.
- (Object) setWidth(width, forSegmentAtIndex:segment)
Sets the width of the specified segment of the receiver.
- (String) titleForSegmentAtIndex(segment)
Returns the title of the specified segment.
- (Hash) titleTextAttributesForState(state)
Returns the text attributes of the title for a given control state. For more details, see setTitleTextAttributes:forState:
- (Float) widthForSegmentAtIndex(segment)
Returns the width of the indicated segment of the receiver.