DrawSignatureView is a simple, light-weight drawing framework written in Swift. Its very easy to implement.
Signature/Drawing component for iOS written in Swift
- iOS 9.0+
- Swift 5.0
DrawSignatureView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DrawSignatureView"
Using DrawSignatureView is very simple:
If you have installed via Cocoapods, you will need to import the module into your Swift file:
import DrawSignatureView
Create a DrawSignatureView through code:
let drawSignatureView = DrawSignatureView(frame: frame)
self.view.addSubview(drawSignatureView)
Create a DrawSignatureView interface builder:
Clears signature
self.drawSignatureView.erase()
-
Signature State by Callback
self.drawSignatureView.currentTouchState = { [weak self] (touchState) in switch touchState { case .began: print("began") case .moved: print("moved") case .ended: print("ended") case .none: print("none") } }
-
Capture Siganture by Callback
self.drawSignatureView.captureSignature { [weak self] (signature) in if let signature = signature { print("Capture Signature: \(signature.image)") print("Capture time: \(signature.date)") self?.captureSignatureImageView.image = signature.image } }
import DrawSignatureView
class ViewController: UIViewController {
// Connect this Outlet to the DrawSignatureView
@IBOutlet weak private var drawSignatureView: DrawSignatureView!
@IBOutlet weak private var captureSignatureImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.signatureState()
}
/// Signature State by CallBack
private func signatureState() {
self.drawSignatureView.currentTouchState = { [weak self] (touchState) in
switch touchState {
case .began:
print("began")
case .moved:
print("moved")
case .ended:
print("ended")
case .none:
print("none")
}
}
}
/// Clear Signature
@IBAction func clearSignature(_ sender: UIButton) {
self.captureSignatureImageView.image = nil
self.drawSignatureView.erase()
}
/// Capture Siganture
@IBAction func captureSignature(_ sender: UIButton) {
self.drawSignatureView.captureSignature { [weak self] (signature) in
if let signature = signature {
print("Capture Signature: \(signature.image)")
print("Capture time: \(signature.date)")
self?.captureSignatureImageView.image = signature.image
}
}
}
}
- If you found a bug, please open an issue. 🙇
- Also, if you have a feature request, please open an issue. 👍
- If you want to contribute, submit a pull request.:muscle:
Mohd Tahir, @Mohd_Tahir99