Simple gesture password in swift.


  • Use delegate for gesture view to pass password
  • Use CAShapeLayer、UIBezeierPath to draw for good performance
  • Support define 3*34*4... Matrix
  • Support define many kinds of normal and selected style
  • Use KeyChain and UserDefaults to save informations


  • iOS 8.0+
  • Xcode 9.0+
  • Swift 4.0+



pod "GPassword"

or you can drag Source folder into your project.


First custom UI style, here is what you need:

GPassword.config { (options) in
    options.connectLineStart = .border
    options.normalstyle = .innerFill
    options.isDrawTriangle = true
    options.matrixNum = 3

then you can use Box.swift or add it to a UIViewController

fileprivate lazy var passwordBox: Box = {
    let box = Box(frame: CGRect(x: 50, y: 200, width: GWidth - 2 * 50, height: 400))
    box.delegate = self
    return box

then you need to achieve two delegate methods, you should write business logics in them, sendTouchPoint can send out complete password and touchesEnded can deal business logics according to type(setting/verify/modify)

extension PasswordViewController: EventDelegate {
    func sendTouchPoint(with tag: String) {
        password += tag
        // get complete password
    func touchesEnded() {
        // write business logics according to type

more informations you can see PasswordViewController.swift in demo project, I write an example.