The base class for controls, which are visual elements that convey a specific action or intention in response to user interactions.


@interface UIControl : UIView


Controls implement elements such as buttons and sliders, which your app might use to facilitate navigation, gather user input, or manipulate content. Controls use the Target-Action mechanism to report user interactions to your app.

Figure 1

Examples of UIKit controls

You do not create instances of this class directly. The UIControl class is a subclassing point that you extend to implement custom controls. You can also subclass existing control classes to extend or modify their behaviors. For example, you might override the methods of this class to track touch events yourself or to determine when the state of the control changes.

A control’s state determines its appearance and its ability to support user interactions. Controls can be in one of several states, which are defined by the UIControlState type. You can change the state of a control programmatically based on your app’s needs. For example, you might disable a control to prevent the user from interacting with it. User interactions can also change the state of a control.

The Target-Action Mechanism

Controls use the target-action mechanism to report interesting events happening to your code. The target-action mechanism simplifies the code that you write to use controls in your app. Instead of writing code to track touch events, you write action methods to respond to control-specific events. For example, you might write an action method that responds to changes in the value of a slider. The control handles all the work of tracking incoming touch events and determining when to call your methods.

When adding an action method to a control, you specify both the action method and an object that defines that method to the addTarget:action:forControlEvents: method. (You can also configure the target and action of a control in Interface Builder.) The target object can be any object, but it is typically the view controller whose root view contains the control. If you specify nil for the target object, the control searches the responder chain for an object that defines the specified action method.

The signature of an action method takes one of three forms, which are listed in Listing 1. The sender parameter corresponds to the control that calls the action method, and the event parameter corresponds to the UIEvent object that triggered the control-related event.

Listing 1

Action method definitions

- (IBAction)doSomething;
- (IBAction)doSomething:(id)sender;
- (IBAction)doSomething:(id)sender forEvent:(UIEvent*)event;

Action methods are called when the user interacts with the control in specific ways. The UIControlEvents type defines the types of user interactions that a control can report and those interactions mostly correlate to specific touch events within the control. When configuring a control, you must specify which events trigger the calling of your method. For a button control, you might use the UIControlEventTouchDown or UIControlEventTouchUpInside event to trigger calls to your action method. For a slider, you might care only about changes to the slider’s value changes and so you might choose to attach your action method to UIControlEventValueChanged events.

When a control-specific event occurs, the control calls any associated action methods right away. Action methods are dispatched through the current UIApplication object, which finds an appropriate object to handle the message, following the responder chain if needed. For more information about responders and the responder chain, see Event Handling Guide for UIKit Apps.

Interface Builder Attributes

Table 1 lists the attributes associated with instances of the UIControl class.

Table 1

Control attributes




The horizontal and vertical alignment of a control’s content. For controls that contain text or images, such as buttons and text fields, use these attributes to configure the position of that content within the control’s bounds.

These alignment options apply to the content of a control and not to the control itself. For information about how to align controls with respect to other controls and views, see Auto Layout Guide.


The initial state of the control. Use the checkboxes to configure whether the control is enabled, selected, or highlighted initially.


Because UIControl is an abstract class, you do not internationalize it specifically. However, you do internationalize the content of subclasses like UIButton. For information about internationalizing a specific control, see the reference for that control.


Controls are accessible by default. To be useful, an accessible user interface element must provide accurate and helpful information about its screen position, name, behavior, value, and type. This is the information VoiceOver speaks to users. Visually impaired users can rely on VoiceOver to help them use their devices.

Controls support the following accessibility attributes:

  • Label. A short, localized word or phrase that succinctly describes the control or view, but does not identify the element’s type. Examples are “Add” or “Play.”

  • Traits. A combination of one or more individual traits, each of which describes a single aspect of an element’s state, behavior, or usage. For example, an element that behaves like a keyboard key and that is currently selected can be characterized by the combination of the Keyboard Key and Selected traits.

  • Hint. A brief, localized phrase that describes the results of an action on an element. Examples are “Adds a title” or “Opens the shopping list.”

  • Frame. The frame of the element in screen coordinates, which is given by the CGRect structure that specifies an element’s screen location and size.

  • Value. The current value of an element, when the value is not represented by the label. For example, the label for a slider might be “Speed,” but its current value might be “50%.”

The UIControl class provides default content for the value and frame attributes. Many controls enable additional specific traits automatically as well. You can configure other accessibility attributes programmatically or using the Identity inspector in Interface Builder.

For more information about accessibility attributes, see Accessibility Programming Guide for iOS.

Subclassing Notes

Subclassing UIControl gives you access to the built-in target-action mechanism and simplified event-handling support. You can subclass existing controls and modify its behavior in one of two ways:

If you subclass UIControl directly, your subclass is responsible for setting up and managing your control’s visual appearance. Use the methods for tracking events to update your control’s state and to send an action when the control’s value changes.


Configuring the Control’s Attributes


The state of the control, specified as a bitmask value.


A Boolean value indicating whether the control is enabled.


A Boolean value indicating whether the control is in the selected state.


A Boolean value indicating whether the control draws a highlight.


The vertical alignment of content within the control’s bounds.


Constants for specifying the vertical alignment of content (text and images) in a control.


The horizontal alignment of content within the control’s bounds.


The horizontal alignment currently in effect for the control.


The horizontal alignment of content (text and images) within a control.

Accessing the Control’s Targets and Actions

- addTarget:action:forControlEvents:

Associates a target object and action method with the control.

- removeTarget:action:forControlEvents:

Stops the delivery of events to the specified target object.

- actionsForTarget:forControlEvent:

Returns the actions performed on a target object when the specified event occurs.


Returns the events for which the control has associated actions.


Returns all target objects associated with the control.

Triggering Actions

- sendAction:to:forEvent:

Calls the specified action method.

- sendActionsForControlEvents:

Calls the action methods associated with the specified events.

Tracking Touches and Redrawing Controls

- beginTrackingWithTouch:withEvent:

Called when a touch event enters the control’s bounds.

- continueTrackingWithTouch:withEvent:

Called when a touch event associated with the control is updated.

- endTrackingWithTouch:withEvent:

Called when a touch event associated with the control ends.

- cancelTrackingWithEvent:

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


A Boolean value indicating whether the control is currently tracking touch events.


A Boolean value indicating whether a tracked touch event is currently inside the control’s bounds.



Constants describing the types of events possible for controls.


Constants describing the state of a control.


Inherits From

See Also



A control that executes your custom code in response to user interactions.


A control used for the inputting of date and time values.


A control that displays a horizontal series of dots, each of which corresponds to a page in the app’s document or other data-model entity.


A horizontal control made of multiple segments, each segment functioning as a discrete button.


A control used to select a single value from a continuous range of values.


A control used to increment or decrement a value.


A control that offers a binary choice, such as On/Off.