Topics

#53: Signatures with Jot 🖋

Topics

Jot is an awesome library from Laura Skelton and the team at IFTTT.

It makes it easy to add drawing and text overlay capabilities to your app. Today we're going to use it to build a view controller that will allow our users to sign their name on the screen using their finger. Let's get started.

We start with the "Single View" template and import jot.

We instantiate a new JotViewController, and add it as a child view controller of our SignatureViewController. We'll do this inside viewDidLoad:

class SignatureViewController: UIViewController {
  var jotViewController: JotViewController?

  override func viewDidLoad() {
    super.viewDidLoad()

    jotViewController = JotViewController()
    addChildViewController(jotViewController!)

    view.addSubview(jotViewController!.view)
    jotViewController!.didMoveToParentViewController(self)
    jotViewController!.view.frame = view.frame
  }
}

Now comes the fun part. We set the JotViewController's state to be .Drawing and its drawing color to black:

jotViewController!.drawingColor = UIColor.blackColor()
jotViewController!.state = .Drawing

If you launch the app now, you'll see you can now sign your name on the screen!

We finish things off with a Done button and some instructions. Finally, we can grab the image of the signature like this:

jotViewController!.renderImageOnColor(UIColor.whiteColor())

Download the final project here: j.mp/bite053

More info about Jot can be found at git.io/jot