How do I disable user interaction of switch?
hardikamal opened this issue · 2 comments
hardikamal commented
Hi @DanielDahan @OrkhanAlikhanov,
I have tried using mySwitch.isUserInteractionEnabled = false & mySwitch.isEnable = false, Still the switch is responding on touch. How do I disable the touch response of switch?
Thanks
daniel-jonathan commented
Hi @hardikamal that is strange. Is this a recent behavior? We will take a look.
adamdahan commented
This works for me:
import UIKit
import Material
class ViewController: UIViewController {
private var switchControl: Switch!
// MARK: - View lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setup()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layout()
}
// MARK: - Setup
private func setup() {
setupSwitch()
}
private func setupSwitch() {
switchControl = Switch(state: .off, size: .large)
switchControl.buttonOffColor = UIColor.darkGray
switchControl.trackOffColor = UIColor.lightGray
switchControl.buttonOnColor = UIColor.blue
switchControl.trackOnColor = UIColor.blue.withAlphaComponent(0.5)
switchControl.isUserInteractionEnabled = false
view.addSubview(switchControl)
}
// MARK: - Layout
private func layout() {
layoutSwitch()
}
private func layoutSwitch() {
switchControl.frame = CGRect(
center: view.center,
size: CGSize(width: 200, height: 40)
)
}
}
Can you reopen ticket and send snippet of code if the issue still persists?
Thank you!