Skip to content

Instantly share code, notes, and snippets.

@factoryhr
Last active March 15, 2019 11:21
Show Gist options
  • Save factoryhr/8a7bd278a3018097895c09a7df3b5bde to your computer and use it in GitHub Desktop.
Save factoryhr/8a7bd278a3018097895c09a7df3b5bde to your computer and use it in GitHub Desktop.
#1
import LookingForMagentoDevsThatWillProvideFunctionalityToThisAwesomeSwitch
#2
var customSwitch: CustomSwitch = {
let customSwitch = CustomSwitch()
customSwitch.translatesAutoresizingMaskIntoConstraints = false
customSwitch.onTintColor = UIColor.orange
customSwitch.offTintColor = UIColor.darkGray
customSwitch.cornerRadius = 0.1
customSwitch.thumbCornerRadius = 0.1
customSwitch.thumbTintColor = UIColor.white
customSwitch.animationDuration = 0.25
return customSwitch
}()
#3
override func viewDidLoad() {
super.viewDidLoad()
self.setupUI()
}
private func setupUI() {
self.view.addSubview(customSwitch)
setupConstraints()
}
#4
private func setupConstraints(){
NSLayoutConstraint.activate([
customSwitch.topAnchor.constraint(equalTo: self.view.centerYAnchor),
customSwitch.centerXAnchor.constraint(equalTo: self.view.centerXAnchor),
customSwitch.widthAnchor.constraint(equalToConstant: 80),
customSwitch.heightAnchor.constraint(equalToConstant: 30)])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment