To run the example project, clone the repo, and run pod install
from the Example directory first.
JPSwitchButton is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "JPSwitchButton"
let switchButton = JPSwitchButton(frame: buttonFrame, offColor: .white, onColor: blue, image: nil, title: "Press me to turn on", description: "Currently I am off", isOn: false)
let twitterButton = JPSwitchButton(frame: buttonFrame2, offColor: .white, onColor: twitterBlue, image: #imageLiteral(resourceName: "twitter_on"), title: "Connect with Twitter", description: "Add your twitter account!")
You can choose what happens when your button is clicked by writing your code inside the block
switchButton.onClick = {
switchButton.switchState()
switchButton.buttonTitle = switchButton.isOn ? "Press me to turn off" : "Press me to turn on"
switchButton.buttonDescription = switchButton.isOn ? "Currently I am on" : "Currently I am off"
}
Create different action for a long press
twitterButton.onLongPress = {
if twitterButton.isOn {
let url = URL(string: "http://twitter.com/\(username)")!
UIApplication.shared.openURL(url)
}
}
Will turn it off if on, and vice versa
switchButton.onClick = {
switchButton.switchState()
}
switchButton.onClick = {
switchButton.turnOn()
}
switchButton.onClick = {
switchButton.turnOff()
}
julp04, julpanucci@gmail.com
JPSwitchButton is available under the MIT license. See the LICENSE file for more info.