A Swift 5 stateful switch which requires a long press to toggle. A loading indicator will display progress in the button.
Example • Setup • Interface Builder
-
Checkout Repo and add
SafetySwitch/Switchfolder to your project.
Add the repo as a submodule for future updates. -
Drag an
UIViewto your Storyboard and link withSafetySwitch. -
Implement or subclass
SafetySwitch.
When subclassing, 3 methods can be implemented. At leastcompleteTransitionis mandatory for customizing toggling functionality.
override func startTransition() {
isAnimating = true
// your code here
}
override func abortTransition() {
isAnimating = false
// your abortion code here
}
override func completeTransition() {
isAnimating = false
isOn.toggle()
// your toggle Code here
}The Switch can be customized in Storyboard Mode / Interface Builder.
By default, layouting will be done by width of the view. A 1:1 aspect ration constraint with fixed height will give the best experience.

