Class: UIControl

Inherits:
UIView show all

Overview

UIControl is the base class for control objects such as buttons and sliders that convey user intent to the application. You cannot use the UIControl class directly to instantiate controls. It instead defines the common interface and behavioral structure for all its subclasses.

Direct Known Subclasses

UIButton, UIDatePicker, UIPageControl, UIRefreshControl, UISegmentedControl, UISlider, UIStepper, UISwitch, UITextField

Instance Attribute Summary (collapse)

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 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

- (UIControlContentHorizontalAlignment) contentHorizontalAlignment

The horizontal alignment of content (text or image) within the receiver. The value of this property is a constant that specifies the alignment of text or image within the receiver. The default is UIControlContentHorizontalAlignmentLeft.

- (UIControlContentVerticalAlignment) contentVerticalAlignment

The vertical alignment of content (text or image) within the receiver. This value of this property is a constant that specifies the alignment of text or image within the receiver. The default is UIControlContentVerticalAlignmentTop.

- (Boolean) enabled

A Boolean value that determines whether the receiver is enabled. Specify YES to make the control enabled; otherwise, specify NO to make it disabled. The default value is YES. If the enabled state is NO, the control ignores touch events and subclasses may draw differently.

Returns:

  • (Boolean)

- (Boolean) highlighted

A Boolean value that determines whether the receiver is highlighted. Specify YES if the control is highlighted; otherwise NO. By default, a control is not highlighted. UIControl automatically sets and clears this state automatically when a touch enters and exits during tracking and when there is a touch up.

Returns:

  • (Boolean)

- (Boolean) selected

A Boolean value that determines the receiver’s selected state. Specify YES if the control is selected; otherwise NO. The default is NO. For many controls, this state has no effect on behavior or appearance. But other subclasses (for example, UISwitchControl) or the application object might read or set this control state.

Returns:

  • (Boolean)

- (UIControlState) state (readonly)

A Boolean value that indicates the state of the receiver. (read-only) One or more UIControlState bit-mask constants that specify the state of the UIControl object; for information on these constants, see “Control State.” Note that the control can be in more than one state, for example, both disabled and selected (UIControlStateDisabled | UIControlStateSelected).This attribute is read only—there is no corresponding setter method.

Returns:

  • (UIControlState)

- (Boolean) touchInside (readonly)

A Boolean value that indicates whether a touch is inside the bounds of the receiver. (read-only) The value is YES if a touch is inside the receiver’s bounds; otherwise the value is NO.

Returns:

  • (Boolean)

- (Boolean) tracking (readonly)

A Boolean value that indicates whether the receiver is currently tracking touches related to an event. (read-only) The value is YES if the receiver is tracking touches; otherwiseNO.

Returns:

  • (Boolean)

Instance Method Details

- (Array) actionsForTarget(target, forControlEvent:controlEvent)

Returns the actions that are associated with a target and a particular control event. Pass in a selector name to the NSSelectorFromString function to obtain the selector (SEL) value.

Parameters:

  • target (Object)

    The target object—that is, the object to which an action message is sent. You must pass an explicit match for the target. Do not pass a value of nil.

  • controlEvent (UIControlEvents)

    A single constant of type UIControlEvents that specifies a particular user action on the control; for a list of these constants, see “Control Events.”

Returns:

  • (Array)

    An array of selector names as NSString objects or nil if there are no action selectors associated with the control event.

- (Object) addTarget(target, action:action, forControlEvents:controlEvents)

Adds a target and action for a particular event (or events) to an internal dispatch table. You may call this method multiple times, and you may specify multiple target-action pairs for a particular event. The action message may optionally include the sender and the event as parameters, in that order.When you call this method, target is not retained.

Parameters:

  • target (Object)

    The target object—that is, the object to which the action message is sent. If this is nil, the responder chain is searched for an object willing to respond to the action message.

  • action (Symbol)

    A selector identifying an action message. It cannot be NULL.

  • controlEvents (UIControlEvents)

    A bitmask specifying the control events for which the action message is sent. See “Control Events” for bitmask constants.

Returns:

- (UIControlEvents) allControlEvents

Returns all control events associated with the receiver.

Returns:

  • (UIControlEvents)

    One or more UIControlEvents constants that specify the current control events associated with the receiver; for a list of these constants, see “Control Events”list of all events that have at least one action.

- (NSSet) allTargets

Returns all target objects associated with the receiver.

Returns:

  • (NSSet)

    A set of all targets—that is, the objects to which action messages are sent—for the receiver. The set may include NSNull to indicate at least one nil target (meaning, the responder chain is searched for a target).

- (Boolean) beginTrackingWithTouch(touch, withEvent:event)

Sent to the control when a touch related to the given event enters the control’s bounds.

Parameters:

  • touch (UITouch)

    A UITouch object that represents a touch on the receiving control during tracking.

  • event (UIEvent)

    An event object encapsulating the information specific to the user event.

Returns:

  • (Boolean)

    YES if the receiver is set to respond continuously or set to respond when a touch is dragged; otherwise NO.

- (Object) cancelTrackingWithEvent(event)

Tells the control to cancel tracking related to the given event.

Parameters:

  • event (UIEvent)

    An event object encapsulating the information specific to the user event. This parameter might be nil, indicating that the cancelation was caused by something other than an event, such as the view being removed from the window.

Returns:

- (Boolean) continueTrackingWithTouch(touch, withEvent:event)

Sent continuously to the control as it tracks a touch related to the given event within the control’s bounds.

Parameters:

  • touch (UITouch)

    A UITouch object that represents a touch on the receiving control during tracking.

  • event (UIEvent)

    An event object encapsulating the information specific to the user event

Returns:

  • (Boolean)

    YES if touch tracking should continue; otherwise NO.

- (Object) endTrackingWithTouch(touch, withEvent:event)

Sent to the control when the last touch for the given event completely ends, telling it to stop tracking.

Parameters:

  • touches (UITouch)

    A UITouch object that represents a touch on the receiving control during tracking.

  • event (UIEvent)

    An event object encapsulating the information specific to the user event.

Returns:

- (Object) removeTarget(target, action:action, forControlEvents:controlEvents)

Removes a target and action for a particular event (or events) from an internal dispatch table.

Parameters:

  • target (Object)

    The target object—that is, the object to which the action message is sent. Pass nil to remove all targets paired with action and the specified control events.

  • action (Symbol)

    A selector identifying an action message. Pass NULL to remove all action messages paired with target.

  • controlEvents (UIControlEvents)

    A bitmask specifying the control events associated with target and action. See “Control Events” for bitmask constants.

Returns:

- (Object) sendAction(action, to:target, forEvent:event)

In response to a given event, forwards an action message to the application object for dispatching to a target. UIControl implements this method to forward an action message to the singleton UIApplication object (in its sendAction:to:fromSender:forEvent: method) for dispatching it to the target or, if there is no specified target, to the first object in the responder chain that is willing to handle it. Subclasses may override this method to observe or modify action-forwarding behavior. The implementation of sendActionsForControlEvents: might call this method repeatedly, once for each specified control event.

Parameters:

  • action (Symbol)

    A selector identifying an action message. It cannot be NULL.

  • target (Object)

    The target object—that is, the object to which the action message is sent. If this is nil, the receiver traverses the responder chain and sends the action message to the first object willing to respond to it.

  • event (UIEvent)

    An object representing the event (typically in a UIControl object) that originated the action message. The event can be nil if the action is invoked directly instead of being caused by an event. For example, a value-changed message might be sent for programmatic reasons rather than as a result of the user touching the control.

Returns:

- (Object) sendActionsForControlEvents(controlEvents)

Sends action messages for the given control events. UIControl implements this method to send all action messages associated with controlEvents, repeatedly invoking sendAction:to:forEvent: in the process. The list of targets and actions it looks up is constructed from prior invocations of addTarget:action:forControlEvents:.

Parameters:

  • controlEvents (UIControlEvents)

    A bitmask whose set flags specify the control events for which action messages are sent. See “Control Events” for bitmask constants.

Returns: