<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISwitch",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISwitch"
  },
  "title" : "UISwitch"
}
-->

# UISwitch

A control that offers a binary choice, such as on/off.

```
@MainActor class UISwitch
```

## Overview

The [`UISwitch`](/documentation/UIKit/UISwitch) class declares a property and a method to control its on/off state. When a person manipulates the switch control (“flips” it), it triggers the [`valueChanged`](/documentation/UIKit/UIControl/Event/valueChanged) event.

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

For information about basic view behaviors, see [View Programming Guide for iOS](https://developer.apple.com/library/archive/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009503).

## Topics

### Creating a switch

[`init(frame:)`](/documentation/UIKit/UISwitch/init(frame:))

Creates a switch control.

[`init(coder:)`](/documentation/UIKit/UISwitch/init(coder:))

Creates a switch control from data in an unarchiver.

### Setting the on/off state

[`isOn`](/documentation/UIKit/UISwitch/isOn)

A Boolean value that determines whether the switch is in the on or off position.

[`setOn(_:animated:)`](/documentation/UIKit/UISwitch/setOn(_:animated:))

Sets the state of the switch to the on or off position, optionally animating the transition.

### Setting the display style

[Displaying a checkbox in your Mac app built with Mac Catalyst](/documentation/UIKit/displaying-a-checkbox-in-your-mac-app-built-with-mac-catalyst)

Present a switch control as a Mac-style checkbox when your app runs in the Mac user interface idiom.

[`preferredStyle`](/documentation/UIKit/UISwitch/preferredStyle)

The preferred display style for the switch.

[`style`](/documentation/UIKit/UISwitch/style-swift.property)

The display style for the switch.

[`UISwitch.Style`](/documentation/UIKit/UISwitch/Style-swift.enum)

Styles that determine the appearance of the switch.

[`title`](/documentation/UIKit/UISwitch/title)

The title displayed next to a checkbox-style switch.

### Customizing the appearance of the switch

[`onTintColor`](/documentation/UIKit/UISwitch/onTintColor)

The color used to tint the appearance of the switch when it’s in the on position.

[`thumbTintColor`](/documentation/UIKit/UISwitch/thumbTintColor)

The color used to tint the appearance of the thumb.

### Deprecated

[`onImage`](/documentation/UIKit/UISwitch/onImage)

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

[`offImage`](/documentation/UIKit/UISwitch/offImage)

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



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)