SmileLock
一个用于创建漂亮的密码锁视图的库,也支持Touch ID。
要求
- iOS 9.0+
- Swift 4 (pod版本3.x), Swift 3 (pod版本2.x), Swift 2.3 (pod版本1.x)
它能为您提供什么?
1. 简单创建漂亮的密码锁视图。
let kPasswordDigit = 6
passwordContainerView = PasswordContainerView.create(withDigit: kPasswordDigit)
2. 输入密码完成代理回调。
let passwordContainerView: PasswordContainerView = ...
passwordContainerView.delegate = self
extension ViewController: PasswordInputCompleteProtocol {
func passwordInputComplete(passwordContainerView: PasswordContainerView, input: String) {
print("input completed -> \(input)")
//handle validation wrong || success
}
}
3. Touch ID 和 Face ID
感谢 Piotr Sochalewski 的贡献。
extension ViewController: PasswordInputCompleteProtocol {
func touchAuthenticationComplete(passwordContainerView: PasswordContainerView, success: Bool) {
if success {
//authentication success
} else {
passwordContainerView.clearInput()
}
}
}
Face ID 要求
使用 Face ID 需要将 NSFaceIDUsageDescription
添加到您的 Info.plist
,否则尝试使用时会崩溃。
4. 自定义 UI。
passwordContainerView.tintColor = UIColor.color(.textColor)
passwordContainerView.highlightedColor = UIColor.color(.blue)
5. 视觉效果。
如果您想看到无视觉效果,请将 HomeViewController.swift
中的属性 isBlurUI
改为 false
。
如何在项目中使用它?
SmileLock 可以通过使用 CocoaPods 来获得。
要安装,只需在您的 Podfile 中添加以下行
pod 'SmileLock'
或者您可以将SmileLock 文件夹拖到您的项目中。
另一种方法
您可以为 PasswordUIValidation
创建子类以编写更简单、更优雅的代码。更多详情请参阅 BlurPasswordLoginViewController.swift
。
override func viewDidLoad() {
super.viewDidLoad()
//create PasswordUIValidation subclass
passwordUIValidation = MyPasswordUIValidation(in: passwordStackView)
passwordUIValidation.success = { [weak self] _ in
print("*️⃣ success!")
self?.alertForRightPassword { _ in
self?.passwordUIValidation.resetUI()
}
}
passwordUIValidation.failure = { _ in
//do not forget add [weak self] if the view controller become nil at some point during its lifetime
print("*️⃣ failure!")
}
...
}
贡献
- 热切欢迎您提交拉取请求。
鸣谢
SmileLock 由 RECRUIT LIFESTYLE CO., LTD. 拥有和维护。
许可
Copyright (c) 2016 RECRUIT LIFESTYLE CO., LTD.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.