Class

UISwitch

You use the UISwitch class to create and manage the On/Off buttons used, for example, in the Settings app for options such as Airplane Mode and Bluetooth. These objects are known as switches.

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.

For more information about appearance and behavior configuration, see Switches.

Symbols

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?

The image displayed when the switch is in the on position.

var offImage: UIImage?

The image displayed while the switch is in the off position.

Relationships

Inherits From

Conforms To