Giter Site home page Giter Site logo

pujiaxin33 / jxpatternlock Goto Github PK

View Code? Open in Web Editor NEW
234.0 3.0 24.0 115 KB

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

License: MIT License

Swift 98.24% Objective-C 0.79% Ruby 0.97%
pattern patternlock patternlockview gesturepassword password lock gesture

jxpatternlock's Introduction

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。

使用过程中,有任何建议或问题,可以通过以下方式联系我:
邮箱:[email protected]

喜欢就star❤️一下吧

License

JXPatternLock is released under the MIT license.

jxpatternlock's People

Contributors

pujiaxin33 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jxpatternlock's Issues

iPad problem

Hello, great control. thanks. Only problem, it crashes on iPad.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.