alankarmisra / SwiftSignatureView

A lightweight, fast and customizable option for capturing fluid, variable-stroke-width signatures within your app.
MIT License
320 stars 93 forks source link

SwiftSignatureView (now with PencilKit!)

Version License Platform

Description

SwiftSignatureView is a lightweight, fast and customizable option for capturing signatures within your app. You can retrieve the signature as a UIImage. With code that varies the pen width based on the speed of the finger movement, the view generates fluid, natural looking signatures. And now, with iOS13+, SwiftSignatureView automatically uses PencilKit to provide a native and even more fluid signature experience, including a natural integration with the Apple Pencil which makes SwiftSignatureView even better!

Sample

Version 3.2.1

Version 3.2.0

Version 3.0.0

Known issues

Version 2.2.3 | Swift 5.0

Version 2.2.2 | Swift 5.0

Version 2.2.0 | Swift 5.0

[ A big thank you to all the contributors. I know I don't say it enough. ]

Version 2.1.0 | Swift 5.0

Version 2.0 | Swift 3.0 / XCode 8

Version 1.0.3 | Swift 2.3 / XCode 8 compatibility

Version 1.0.2 | Callbacks for panning/tapping

Version 1.0.1 | Bug fixes and Syntax updates to Swift 2.2

Version 0.0.8 | Bug fixes

Version 0.0.8 fixes a bug that caused SwiftSignatureView to compute incorrect offsets when not in full-screen mode. A big thank you to Todd Kersey for discovering the bug and suggesting a fix. This update fixes the issue.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

More specifically, you simply assign the SwiftSignatureView class to a UIView, optionally play with the minimum stroke width, maximum stroke width, stroke color and stroke alpha all which are settable from within the Interface Builder itself and you're all set! You can then use the signature property to get a UIImage representation of the signature and the clear method to clear the signature view. For example if you had:

@IBOutlet weak var signatureView: SwiftSignatureView!

you can use

signatureView.signature()

to get a UIImage representation of the signature;

signatureView.getCroppedSignature()

to get a UIImage representation of the cropped signature with the surrounding whitespace trimmed.

signatureView.clear()

to clear the signature view.

Installation

SwiftSignatureView is available through CocoaPods and Swift Package Manager.

For Cocoapods >= 1.0

Add the following lines to your Podfile:

use_frameworks!
target "YOUR_PROJECT_NAME" do
    pod "SwiftSignatureView"
end

For Cocoapods < 1.0

Add the following lines to your Podfile:

use_frameworks!
pod "SwiftSignatureView"

For Swift Package Manager

Add the following lines to your Package.swift file (or just use the Package Manager from within XCode and reference this repo):

dependencies: [
    .package(url: "https://github.com/alankarmisra/SwiftSignatureView.git", from: "3.2.1")
]

Questions? Write in to:

Alankar Misra, alankarmisra@gmail.com

License

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