BHSwipeButton is a subclass of UIButton that allows you within a couple of lines to add a UIButton with a shimmer and the ability for a user to swipe it right in order to perform an action. I wrote it whilst building an iOS application and thought it might be useful in your project.
- Import Facebook's Shimmer Objective-C project (supported on Cocoapods.org)
- Import BHSwipeButton.swift in this gist to your XCode project (must be a version supporting Swift 1.2 or above)
- Once imported, on your storyboard or XIB files set the class for the UIButton you want to customize with
BHSwipeButton
- Within your UIViewController class, you should link your button to
delegate = self
and usesetText("Swipe to do something")
to set text - You should also have a
BHSwipeButtonDelegate
attached - Once you have that, you'll need to implement a function called
func swipeButton(button: BHSwipeButton, userDidSwipeButton animated: Bool)
- That's it! Whenever the user swipes,
class ExampleController : UIViewController, BHSwipeButtonDelegate {
@IBAction var finishSignupButton : BHSwipeButton!
override func viewDidLoad() {
super.viewDidLoad()
self.finishSignupButton.delegate = self
self.finishSignupButton.setTitle("Swipe to finish signup")
}
func swipeButton(button: BHSwipeButton, userDidSwipeButton animated: Bool) {
// User swiped. Sign them up here!
}
}