Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change switch on, off programmatically #644

Closed
bayarmanlai opened this issue Dec 23, 2016 · 2 comments
Closed

How to change switch on, off programmatically #644

bayarmanlai opened this issue Dec 23, 2016 · 2 comments

Comments

@bayarmanlai
Copy link

bayarmanlai commented Dec 23, 2016

2.4.1 release note says Removed Switch.setOn function.

I need to change it's state programmatically. How can I do that.

First time switch state changed, after that it doesn't change it's state when I set isOn variable value programmatically.

@daniel-jonathan
Copy link
Member

daniel-jonathan commented Dec 23, 2016

Please update to Material 2.4.4.

To change the state programmatically, use:

let control = Switch()
control.switchState = .on

or

let control = Switch()
control.setSwitchState(state: .on, animated:  true) { (control) in 
    // Do something
}

or

let control = Switch()
control.isOn = true

If you need any further help, please reopen or create a new issue :)

@bayarmanlai
Copy link
Author

bayarmanlai commented Dec 26, 2016

Thanks, for your update. Now it works as expected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants