Latest 0.1.0
Homepage https://github.com/nukotsuka/MultiDegreeLikeButton
License MIT
Platforms ios 10.0
Authors

CI Status
Version
Carthage compatible
License
Platform

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
MultiDegreeLikeButton MultiDegreeLikeButton

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 to likeDegree.

Author

nukotsuka, @nukotsuka

License

MultiDegreeLikeButton is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MultiDegreeLikeButton",
    "version": "0.1.0",
    "summary": "A button expanding while tapping.",
    "description": "MultiDegreeLikeButton is a button which expresses the degree of like by changing the size of the button.nThe button gradually expands while the user is tapping.nAnd if the button is 3D touched, it immediately expands.",
    "homepage": "https://github.com/nukotsuka/MultiDegreeLikeButton",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "nukotsuka": "[email protected]"
    },
    "source": {
        "git": "https://github.com/nukotsuka/MultiDegreeLikeButton.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "10.0"
    },
    "swift_version": "4.0",
    "source_files": "MultiDegreeLikeButton/Classes/**/*",
    "resources": "MultiDegreeLikeButton/Assets/*.xcassets"
}

Pin It on Pinterest

Share This