Is this possible to disable a UISwitch? I do not mean putting it in an OFF state, I mean disabling user interaction, and having it appear gray.
In my app I have two conditions
if (condition == true) {
// UISwitch should be enabled
} else {
// UISwitch should be visible, but disabled
// e.g uiswitch.enable=NO;
}
Any suggestions?
switch. enabled = NO; or equivalently: [switch setEnabled:NO];
1 Open your iPhone's Settings. 2 Scroll down and tap "Accessibility." 3 Scroll down and tap " Switch Control." 4 Toggle the switch to 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), it triggers the valueChanged event. You can customize the appearance of the switch by changing the color used to tint the switch when it is on or off.
Toggle switch (known as “toggles”) is a UI control that has two mutually-exclusive states, such as ON and OFF. The design and functionality of this control is based on a physical switch that allows users to turn things ON or OFF (i.e. light switch).
This should do it:
switch.enabled = NO;
or equivalently:
[switch setEnabled:NO];
where switch
is whatever your UISwitch
variable name is.
Edit 18-Apr-2018
The answer above is (clearly) an Objective-C solution, written well before anyone had ever heard of Swift. The Swift equivalent solution is, of course:
switch.isEnabled = false
Yes you can. UISwitch
inherits from UIControl
, and UIControl
has an enabled
property. Apple's UIControl Documentation has all of the details.
To enable
switch.enabled = YES;
To disable
switch.enabled = NO;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With