Git Product home page Git Product logo

hapticbutton's Introduction

buddybuild Carthage License Platform Twitter: @BalestraPatrick

HapticButton

๐Ÿ“– Description

HapticButton replicates the behavior of the buttons in the iOS 10 and 11 Control Center as well as in the Home app. A device with 3D Touch is required to fully experience the haptic feedback on supported devices. It is implemented as a subclass of UIControl, so feel free to further customize it to your needs.

The user is required to press the button and activate 3D Touch with a minimum pressure threshold (you can specify the minimum value to trigger the button via the feedbackThreshold property). This allows for a cool interaction that gives a haptic feedback to the user when the button is triggered. ๐Ÿ‘

For the best experience, install the example on a device. ๐Ÿ“ฑ

The example project shows how to set up HapticButton in a few different ways.

  • Create a button with a UILabel. Use the HapticButtonDelegate to be notified when the button is triggered.
@IBOutlet weak var button: HapticButton!
button.mode = .label(text: "Hello! ๐Ÿ‘‹")
// Use the delegate method to be notified when the button is pressed.
button.delegate = self
  • Create a button with a UIImageView and a blur background. Use the standard UIControl event to subscribe to the touch up inside event.
let blurButton = HapticButton(mode: .image(image: #imageLiteral(resourceName: "swift")))
blurButton.addBlurView(style: .light)
// Add custom target selector to the touch up inside event.
blurButton.addTarget(self, action: #selector(blurButtonPressed(_:)), for: .touchUpInside)
  • Create a button with a customized UILabel and dark blur background. Subcribe to the button events through a closure.
let blurButton = HapticButton(mode: .label(text: "Hello Blur!"))
darkBlurButton.textLabel.textColor = .white
darkBlurButton.addBlurView(style: .dark)
// Pass closure to be invoked when the button is pressed.
darkBlurButton.onPressed = {
	print("Dark blur button pressed.")
}

๐ŸŽจ Customizations

These are the public properties that allow you to customize the control. In case you are thinking to modify HapticButton even further, consider creating a Pull Request! ๐Ÿ‘๐Ÿป

public weak var delegate: HapticButtonDelegate?

/// The closure invoked when the button is pressed.
public var onPressed: Callback?

/// The minimum pressure that the button press has to receive in order to trigger the related haptic feedback. The value has to be between 0 and 1 and the default is 0.25.
public var feedbackThreshold = 0.25

/// If the button is in mode `label`, this `UILabel` is part of the button hierarchy. Modify this object directly for more customizations on the displayed text.
public lazy var textLabel: UILabel

/// If the button is in mode `image`, this `UIImageView` is part of the button hierarchy. Modify this object directly for more customizations on the displayed image.
public lazy var imageView: UIImageView

/// The current mode of the button.
public var mode = HapticButtonMode.label(text: "Title")

๐Ÿ”ž Requirements

iOS 10.0 and Swift 3.2 are required.

If you are using Swift 4, please use the swift4 branch.

๐Ÿ›  Installation

HapticButton is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "HapticButton"

You can also use Carthage if you prefer. Add this line to your Cartfile.

github "BalestraPatrick/HapticButton"

๐Ÿ‘จโ€๐Ÿ’ป Author

I'm Patrick Balestra.

Email: [email protected]

Twitter: @BalestraPatrick.

License

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

hapticbutton's People

Contributors

balestrapatrick avatar a2 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.