A lightweight, protocol-facing programming, highly customizable pattern unlock/gesture unlock/gesture password/pattern password/nine grid password

What are the advantages compared with other similar tripartite libraries?

  • Fully protocol oriented programming, support highly customized grid view and connection line view, easy to achieve various needs;
  • Default support for a variety of configuration effects, support most of the mainstream effects, the introduction can fix the demand;
  • Swift5 source code prepared by generics, enumeration, functional programming optimization code, with higher learning value;
  • Later will continue to iterate, continue to add mainstream effect;

Making the address

JXPatternLock

Results the preview

instructions Gif
The arrow
Automatic connection of intermediate points
Gray points
The small white point
Electric blue
The fill white
shadow
The picture
Twirl (Chicken you too beautiful)
Broken line
Picture connection line (arrow)
Picture connection line (Xiaoyuer)
Set the password
Change the password
Verify password

use

Initialize thePatternLockViewConfig

Method 1: UseLockConfig

LockConfig is the class provided by default that implements the PatternLockViewConfig protocol. You can customize it directly through the LockConfig properties.

let config = LockConfig()
config.gridSize = CGSize(width: 70, height: 70)
config.matrix = Matrix(row: 3, column: 3)
config.errorDisplayDuration = 1
Copy the code

Method 2: Create an implementationPatternLockViewConfigThe class of the agreement

In this way, all configuration details can be gathered inside the custom class, and outside the custom class only needs to be initialized. For details, see the ArrowConfig class in Demo. One advantage of this is that if the same configuration is needed in multiple places, you only need to initialize the same class instead of copying the property configuration code as you would with LockConfig.

struct ArrowConfig: PatternLockViewConfig {
    var matrix: Matrix = Matrix(row: 3, column: 3)
    var gridSize: CGSize = CGSize(width: 70, height: 70)
    var connectLine: ConnectLine?
    var autoMediumGridsConnect: Bool = false
    // Other attributes configured! For example only, not all configuration items are displayed, affecting the length of the document
}
Copy the code

configurationGridView

config.initGridClosure = {(matrix) -> PatternLockGrid in
    let gridView = GridView(a)let outerStrokeLineWidthStatus = GridPropertyStatus<CGFloat>.init(normal: 1, connect: 2, error: 2)
    let outerStrokeColorStatus = GridPropertyStatus<UIColor>(normal: tintColor, connect: tintColor, error: .red)
    gridView.outerRoundConfig = RoundConfig(radius: 33, lineWidthStatus: outerStrokeLineWidthStatus, lineColorStatus: outerStrokeColorStatus, fillColorStatus: nil)
    let innerFillColorStatus = GridPropertyStatus<UIColor>(normal: nil, connect: tintColor, error: .red)
    gridView.innerRoundConfig = RoundConfig(radius: 10, lineWidthStatus: nil, lineColorStatus: nil, fillColorStatus: innerFillColorStatus)
    return gridView
}
Copy the code

configurationConnectLine

let lineView = ConnectLineView()
lineView.lineColorStatus = .init(normal: tintColor, error: .red)
lineView.triangleColorStatus = .init(normal: tintColor, error: .red)
lineView.isTriangleHidden = false
lineView.lineWidth = 3
config.connectLine = lineView
Copy the code

Initialize thePatternLockView

lockView = PatternLockView(config: config)
lockView.delegate = self
view.addSubview(lockView)
Copy the code

structure

Fully compliant with protocol-facing development. PatternLockView relies on the configuration protocol PatternLockViewConfig. Configure protocols Configure the grid protocol PatternLockGrid and the connection line protocol ConnectLine.

Making the address

JXPatternLock