Class

UISwitch

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

Overview

The UISwitch class declares a property and a method to control its on/off state. As with UISlider, when the user manipulates the switch control (“flips” it) a UIControlEventValueChanged event is generated, which results in the control (if properly configured) sending an action message.

You can customize the appearance of the switch by changing the color used to tint the switch when it is on or off.

For information about basic view behaviors, see View Programming Guide for iOS.

Topics

Initializing the Switch Object

initWithFrame:

Returns an initialized switch object.

Setting the Off/On State

on

A Boolean value that determines the off/on state of the switch.

setOn:animated:

Set the state of the switch to On or Off, optionally animating the transition.

Customizing the Appearance of the Switch

onTintColor

The color used to tint the appearance of the switch when it is turned on.

tintColor

The color used to tint the outline of the switch when it is turned off.

thumbTintColor

The color used to tint the appearance of the thumb.

onImage

In iOS 6 and earlier, the image displayed when the switch is in the on position.

offImage

In iOS 6 and earlier, the image displayed when the switch is in the off position.

Relationships

Inherits From

Conforms To

See Also

Controls

UIControl

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

UIButton

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

UIDatePicker

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

UIPageControl

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.

UISegmentedControl

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

UISlider

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

UIStepper

A control used to increment or decrement a value.