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

init(frame: CGRect)

Returns an initialized switch object.

Setting the Off/On State

var isOn: Bool

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

func setOn(Bool, animated: Bool)

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

Customizing the Appearance of the Switch

var onTintColor: UIColor?

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

var tintColor: UIColor!

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

var thumbTintColor: UIColor?

The color used to tint the appearance of the thumb.

var onImage: UIImage?

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

var offImage: UIImage?

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

Relationships

Inherits From

Conforms To

See Also

Controls

class UIControl

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

class UIButton

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

class UIDatePicker

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

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

class UISegmentedControl

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

class UISlider

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

class UIStepper

A control used to increment or decrement a value.