Inwizards-blog-img

Create a new project

Open Xcode , create a new “Single Page Application” and select Swift as the programming language.

add source file INSignatureView.h and INSignatureView.m by drag and drop into interface builder to your project.



Add Bridging Header

INSignatureView.h and INSignatureView.m file in objective-c so we have to create bridging header file.

To add bridging header to the project

Create new file by File >> New >> File from the menu to add temporary file.

Select Objective-C File.

Click Next.

Add File Name.

Click on Next.

Click on Create.

It will ask to configure Objective-C bridging header.

Click on Create Bridging Header button.

It will create Objective-C bridging header file.

Add following line of code to Bridging Header file #import “INSignatureView.h”

Now Goto ViewController.swift file

Now create property of signature view,

@IBOutlet weak var SignatureView: INSignatureView!

Drag and drop a UIView for drawing signature and change it’s class from INSignatureView



then connect the outlet with property,

you can see the preview of signature in image view and save into your device also.

Here is the complete Code in ViewController.swift file

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var imgview: UIImageView!

@IBOutlet weak var SignatureView: INSignatureView!

override func viewDidLoad() {

super.viewDidLoad()

}

@IBAction func Capture(sender: AnyObject) {

let image:UIImage = SignatureView.getSignatureImage()

imgview.image = image

UIImageWriteToSavedPhotosAlbum(SignatureView.getSignatureImage(), nil, nil, nil)

}

@IBAction func Reset(sender: AnyObject) {

SignatureView.clearSignature()

imgview.image = nil

}

}



You can download Demo project from given link below :

https://goo.gl/e9o5iP

Enjoy 🙂

Draw Digital Signature in iOS using Swift 2.0

Post navigation


One thought on “Draw Digital Signature in iOS using Swift 2.0

Leave a Reply

Your email address will not be published. Required fields are marked *