测试已测试 | ✗ |
语言编程语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017年8月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 julian Panucci 维护。
要运行示例项目,请克隆代码库,然后首先从 Example 目录中运行 pod install
。
JPSwitchButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 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!")
您可以通过在 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"
}
为长按创建不同的动作
twitterButton.onLongPress = {
if twitterButton.isOn {
let url = URL(string: "http://twitter.com/\(username)")!
UIApplication.shared.openURL(url)
}
}
如果按钮是打开的,则将其关闭,反之亦然
switchButton.onClick = {
switchButton.switchState()
}
switchButton.onClick = {
switchButton.turnOn()
}
switchButton.onClick = {
switchButton.turnOff()
}
julp04, [email protected]
JPSwitchButton 在 MIT 许可下提供。更多信息请参阅 LICENSE 文件。