MultiDegreeLikeButton
MultiDegreeLikeButton is a "like button" which expresses the degree of like by changing the size. The button gradually expands while the user is tapping. And if the button is 3D touched, it immediately expands.
Long press | 3D touch |
---|---|
![]() |
![]() |
Requirements
- iOS 10.0+
- Xcode 10.0+
- Swift 4.0+
Installation
CocoaPods
MultiDegreeLikeButton is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MultiDegreeLikeButton'
Carthage
If you’re using Carthage, simply add
MultiDegreeLikeButton to your Cartfile
:
github 'nukotsuka/MultiDegreeLikeButton'
Usage
Basic
let heartButton = MultiDegreeLikeButton(imageStyle: .heart)
heartButton.completion = { _, degree in
// do something
}
view.addSubview(heartButton)
Custom
let smileButton = MultiDegreeLikeButton(
imageStyle: .custom(defaultImage: "smile_default", tappedImage: "smile_tapped"),
size: CGSize(width: 48, height: 48)
)
// custom properties
smileButton.likeDegree = 10
smileButton.durationLongPress = 5.0
smileButton.duration3DTouch = 0.5
smileButton.durationShrink = 0.5
smileButton.delayBeforeShrink = 0.1
smileButton.threshold3DTouch = 5.0
smileButton.completion = { button, degree in
button.isEnabled = false
// do something
}
view.addSubview(smileButton)
Properties
isEnabled: Bool
: if this value is false,completion
is not called, but animation works.likeDegree: Int
: the degree of like, and this value is used for expanding scale of the button.durationLongPress: Double
: the duration of expanding animation while tapping the button.duration3DTouch: Double
: the duration of expanding animation while 3D touching the button.durationShrink: Double
: the duration of shrinking animation after end of tap.delayBeforeShrink: Double
: the delay from the end of tap until shrinking starts.threshold3DTouch: CGFloat
: the threshold at which 3D touch starts.completionWithLikeDegree: ((MultiDegreeLikeButton, Int) -> Void)?
: the callback function called after tap finishes.Int
argument indicates the degree of like based on the time the user was tapping, and the range is from 1 tolikeDegree
.
Author
nukotsuka, @nukotsuka
License
MultiDegreeLikeButton is available under the MIT license. See the LICENSE file for more info.