Skip to content

denis-kakacka-tg/DKSwitchSlider

Repository files navigation

DKSwitchSlider

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

DKSwitchSlider is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DKSwitchSlider'

Usage

import DKSwitchSlider
lazy var switcher: DKSwitchSlider = {
    let switcher = DKSwitchSlider()
    switcher.translatesAutoresizingMaskIntoConstraints = false
    switcher.onImage = UIImage(named: "icn-on")
    switcher.offImage = UIImage(named: "icn-off")
    switcher.thumbImage = UIImage(named: "icn-power")
    switcher.cornerRadius = 24
    switcher.thumbCornerRadius = 24
    switcher.isOn = true
    switcher.showLabel = true
    switcher.textColor = .white
    switcher.text = "ON"
    switcher.thumbBackgroundColor = .white
    switcher.thumbImageTintColor = .black
    switcher.onImageViewTintColor = .black
    switcher.offImageViewTintColor = .white
    switcher.addTarget(self, action: #selector(animate), for: .valueChanged)

    return switcher
}()
@objc
func animate(sender: DKSwitchSlider) {
    UIView.animate(withDuration: 0.25) {
        self.switcher.text = sender.isOn ? "ON" : "OFF"
        self.switcher.textColor = sender.isOn ? .white : .black
        self.view.backgroundColor = sender.isOn ? UIColor(red: 1, green: 206/255, blue: 84/255, alpha: 1) : .black
    }
}

Author

Denis Kakačka, [email protected]

License

DKSwitchSlider is available under the MIT license. See the LICENSE file for more info.

About

Customizable slider style switch button.

Resources

License

Stars

Watchers

Forks

Packages

No packages published