Animating Heart button inspired by animation within Instagram App.
-
Drag and drop UIView.
-
Set
HeartButton
to Class and Module fields. -
Set the outlet and write the handling code.
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 } } }
You can change the design on the Storyboard.
Or You can change it programmatically.
property | type | default |
---|---|---|
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 is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "HeartButton"
To integrate using Carthage, add the following to your Cartfile:
github "darquro/heart-button"
- Swift 4.0 or later
- iOS 9.0 or later
darquro
HeartButton is available under the MIT license. See the LICENSE file for more info.