AIFlatSwitch
AIFlatSwitch 是一个平滑、美观并且可IBDesignable的平面设计开关,适用于 iOS。它可以替代 UISwitch 使用。
受到了 Creativedash 在 Dribbble 的帖子此处的启发
要求
- iOS 8.0+, tvOS 12.0+
- Xcode 11.0+
- Swift 5
使用方式
创建平面开关
- 可以手动编写,或者
var flatSwitch = AIFlatSwitch(frame: CGRectMake(0, 0, 50, 50))
- 在 Interface Builder 中创建
方法
更改其选中状态
flatSwitch.isSelected = true
- IBInspectable
或者
flatSwitch.setSelected(true, animated: true)
监听其状态变化
@IBAction func handleSwitchValueChange(sender: AnyObject) {
if let flatSwitch = sender as? AIFlatSwitch {
print(flatSwitch.isSelected)
}
}
动画观察回调
flatSwitch.selectionAnimationDidStart = { isSelected in
print("New state: \(isSelected)")
}
flatSwitch.selectionAnimationDidStop = { isSelected in
print("State when animation stopped: \(isSelected)")
}
开关样式
flatSwitch.lineWidth = 2.0
flatSwitch.strokeColor = UIColor.blue
flatSwitch.trailStrokeColor = UIColor.red
flatSwitch.backgroundLayerColor = UIColor.red
flatSwitch.animatesOnTouch = false
- IBInspectable
贡献指南
- 在您的分支中进行更改
- 在 AIFlatSwitch.podspec 文件中提高 pod 版本 (例如,1.0.1 到 1.0.2)
- 确保示例项目可以在模拟器中编译并正常工作
- 在 README.md 中找到对您的源代码更改的引用,并进行更新(例如,方法名称,更改的功能)
- 创建一个拉取请求
许可证
AIFlatSwitch 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。
动画勾选按钮,勾选标记