pujiaxin33 / JXPatternLock

An easy-to-use, powerful, customizable pattern lock view in swift. 图形解锁/手势解锁 / 手势密码 / 图案密码 / 九宫格密码

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

platform languages cocoapods carthage support

An easy-to-use, powerful, customizable pattern lock view in swift. 图形解锁/手势解锁 / 手势密码 / 图案密码 / 九宫格密码

相比于其他同类三方库有哪些优势:

  • 完全面对协议编程,支持高度自定义网格视图连接线视图,轻松实现各类不同需求;
  • 默认支持多种配置效果,支持大部分主流效果,引入就可以搞定需求;
  • 源码采用Swift5编写,通过泛型、枚举、函数式编程优化代码,具有更高的学习价值;
  • 后期会持续迭代,不断添加主流效果;

效果预览

说明 Gif
箭头
中间点自动连接
小灰点
小白点
荧光蓝
fill白色
阴影
图片
旋转(鸡你太美)
破折线
图片连接线(箭头)
图片连接线(小鱼儿)
设置密码
修改密码
验证密码

要求

  • iOS 9.0+
  • Xcode 10.2.1+
  • Swift 5.0

安装

手动

Clone代码,把Sources文件夹拖入项目,就可以使用了;

CocoaPods

target '<Your Target Name>' do
    pod 'JXPatternLock'
end

先执行pod repo update,再执行pod install

Carthage

在cartfile文件添加:

github "pujiaxin33/JXPatternLock"

然后执行carthage update --platform iOS 即可

使用

初始化PatternLockViewConfig

方式一:使用LockConfig

LockConfig是默认提供的类,实现了PatternLockViewConfig协议。可以直接通过LockConfig的属性进行自定义。

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

方式二:新建实现PatternLockViewConfig协议的类

该方式可以将所有配置细节聚集到自定义类的内部,外部只需要初始化自定义类即可。详情请参考demo里面的ArrowConfig类。这样有个好处就是,多个地方都需要用到同样配置的时候,只需要初始化相同的类,而不用像使用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
    //其他属性配置!只是示例,就不显示所有配置项,影响文档长度
}

配置GridView

config.initGridClosure = {(matrix) -> PatternLockGrid in
    let gridView = GridView()
    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
}

配置ConnectLine

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

初始化PatternLockView

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

结构

structure

完全遵从面对协议开发。 PatternLockView依赖于配置协议PatternLockViewConfigPatternLockViewConfig依赖配置网格协议PatternLockGrid和连接线协议ConnectLine

补充

如果刚开始使用JXPatternLock,当开发过程中需要支持某种特性时,请务必先搜索使用文档或者源代码。确认是否已经实现支持了想要的特性。请别不要文档和源代码都没有看,就直接提问,这对于大家都是一种时间浪费。如果没有支持想要的特性,欢迎提Issue讨论,或者自己实现提一个PullRequest。

使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:317437084@qq.com

喜欢就star❤️一下吧

License

JXPatternLock is released under the MIT license.

About

An easy-to-use, powerful, customizable pattern lock view in swift. 图形解锁/手势解锁 / 手势密码 / 图案密码 / 九宫格密码

License:MIT License


Languages

Language:Swift 98.2%Language:Ruby 1.0%Language:Objective-C 0.8%