♥️ Heart Button♥️
动画 Heart 按钮的库,受到 Instagram 应用中 Heart 动画的启发。
使用方法
-
拖拽 UIView。
-
设置
HeartButton
类和模块字段。 -
设置出口并编写处理代码。
import HeartButton class ViewController: UIViewController { @IBOutlet weak var heartButton: HeartButton! override func viewDidLoad() { super.viewDidLoad() self.heartButton.stateChanged = { sender, isOn in if isOn { // selected } else { // unselected } } }
自定义
您可以在 Storyboard 中更改设计。
或者您也可以通过编程方式更改。
属性 | 类型 | 默认值 |
---|---|---|
offLineWidth | CGFloat | 2.0 |
offLineColor | UIColor | UIColor.black |
offFillColor | UIColor | UIColor.clear |
onLineWidth | CGFloat | 0 |
onLineColor | UIColor | UIColor.clear |
onFillColor | UIColor | UIColor(red:0.92, green:0.29, blue:0.35, alpha:1.0) |
通过编程方式更改状态
// Change with animation
self.heartButton.setOn(!self.heartButton.isOn, animated: true)
安装
HeartButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中:
pod "HeartButton"
使用 Carthage 集成,请将以下内容添加到 Cartfile 中
github "darquro/heart-button"
需求
- Swift 4.0或更高版本
- iOS 9.0或更高版本
作者
darquro
许可
HeartButton遵循MIT许可。有关更多信息,请参阅LICENSE文件。