To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 11.0
- Swift 4.0
- Xcode 9
PressableView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PressableView'
To use a PressableView
, simply drag a regular UIView
into your view inside the storyboard. Then assign the class PressableView
to it:
Then, you may assign a custom value for how much the view should shrink when pressed.
The unit for this is %
. Hence, setting it to 0.5
will make the view shrink to half of its original size. Setting it to 1
will make it not shrink at all.
The default value is 0.96
.
Now, hook up any actions, you'd like it to perform. You may use any of the following:
primaryActionTriggered
(acts liketouchUpInside
)touchUpInside
touchDown
touchDragInside
touchDragOutside
You can either hook up the actions directly through the interface builder, or by assigning a target in code:
However, you can also make use of the PressableViewDelegate
.
It holds the following method:
@objc optional func pressableViewDidTrigger(_ pressableView: PressableView)
Note, though, that this delegate method will only be called when primaryActionTriggered
/ touchUpInside
is called - so like a regular button.
To make use of the delegate, make your view controller conform to the protocol first:
class ViewController: UIViewController, PressableViewDelegate
Then, assign the view controller to the _pressableDelegate
property of your PressableVeiw
:
pressableView._pressableDelegate = self
Note, that you can also do this in interface builder.
If you find any bugs, or want to propose enhancements, please make sure to open an issue, or submit a pull request if you have made any changes you'd like for me to merge.
Linus Geffarth, [email protected]
PressableView is available under the MIT license. See the LICENSE file for more info.