DDPinCodeDecorator
Pin Code Decorator 允许您创建一个用于输入密码和 PIN 的控制器。
安装
CocoaPods
通过 CocoaPods 安装 DDPinCodeDecorator
,请在 Podfile 中添加以下行
pod 'DDPinCodeDecorator'
在将 CocoaPods 安装到您的项目后,使用以下方式导入 DDPinCodeDecorator
import DDPinCodeDecorator
手动安装
将 DDPinCodeDecorator
文件夹添加到您的 Xcode 项目中。
使用方法
请参阅示例 Xcode 项目。
基础配置
创建一个遵循 DDPinCodeDecoratorProtocol
协议的 DDPinCodeDecorator
实例。
let pinCodeDecorator: DDPinCodeDecoratorProtocol = DDPinCodeDecorator(frame: frame)
为了实现最小功能,您必须设置以下参数:
/*
The array with secure images.
The number of pictures is equal to the number of symbols (icons).
*/
var secureImagesArray: [UIImage] { get set }
/*
The image for initial display of all icons
*/
var emptyImage: UIImage { get set }
设置 delegate
并实现 DDPinCodeDecoratorOutput
的以下 delegate
方法:
/*
Optional
Called when all symbols are set
*/
func provideResult(module: DDPinCodeDecoratorProtocol, result: String)
将 DDPinCodeDecorator
的 view
作为 subview
添加。
/*
The view that the decorator manages.
*/
var view: UITextField? { get }
要添加或删除字符,请使用以下方法:
func addSymbol(_ symbol: String)
func delSymbol()
考虑一个示例
let pinCodeDecorator: DDPinCodeDecoratorProtocol = DDPinCodeDecorator(frame: .zero)
pinCodeDecorator.delegate = self
pinCodeDecorator.secureImagesArray = appleImages // is not empty array needed
pinCodeDecorator.emptyImage = emptyAppleImage // is not nil needed
pinCodeDecorator.successImage = successAppleImage
pinCodeDecorator.unsuccessImage = unsuccessAppleImage
pinCodeDecorator.padding = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
pinCodeDecorator.shadow = DDPinCodeDecoratorShadowModel(color: UIColor.black,
opacity: 0.5,
offSet: CGSize(width: 1, height: 1),
radius: 5,
scale: true)
pinCodeDecorator.font = UIFont.systemFont(ofSize: 24)
pinCodeDecorator.symbolOffset = UIOffset(horizontal: 0, vertical: 3)
pinCodeDecorator.secureDelay = 0.2
pinCodeDecorator.isEnableKeyboard = false
guard let appleView = pinCodeDecorator.view else { return }
pinCodeContenView.addSubview(appleView)
...
// in some method someButtonDidTouch e.g.
pinCodeDecorator.addSymbol(symbol)
// or
pinCodeDecorator.delSymbol()
...
// delegate method called
func provideResult(module: DDPinCodeDecoratorProtocol, result: String) {
if module === self.pinCodeDecorator {
if result == "1234" {
module.showSuccess()
} else {
module.showUnsuccess()
animate(module: module)
}
}
}
自定义
/*
The view that the decorator manages.
*/
var view: UITextField? { get }
/*
The string that contains entered characters
Default is ""
*/
var resultString: String { get }
/*
The receiver’s delegate.
*/
var delegate: DDPinCodeDecoratorOutput? { get set}
/*
The font used to display the text.
Default is UIFont.systemFont(ofSize: 14)
*/
var font: UIFont? { get set }
/*
The shadow used to display the icons.
Default is:
color = UIColor.black
opacity = 0.5
offSet = CGSize(width: 1.0, height: 1.0)
radius = 5
scale = true
*/
var shadow: DDPinCodeDecoratorShadowModel? { get set }
/*
The delay from the symbol is displayed until the secure image is displayed
Default is 0.2
*/
var secureDelay: Double? { get set }
/*
A Boolean value that determines whether the keyboard is accessible
Default is true
*/
var isEnableKeyboard: Bool? { get set }
/*
The array with secure images.
The number of pictures is equal to the number of symbols (icons).
*/
var secureImagesArray: [UIImage] { get set }
/*
The image for initial display of all icons
*/
var emptyImage: UIImage { get set }
/*
The image of all icons to display successful input
*/
var successImage: UIImage { get set }
/*
The image of all icons to display unsuccessful input
*/
var unsuccessImage: UIImage { get set }
func addSymbol(_ symbol: String)
func delSymbol()
func showSuccess()
func showUnsuccess()
/*
Do not allow user to enter symbols
*/
func stopTapping()
func allowTapping()
func showKeyboard()
func hideKeyboard()
/*
Display all icons as initial and remove all symbols
*/
func clear()
/*
Optional
Insets for all icons
Default is .zero
*/
var padding: UIEdgeInsets { get set }
var symbolOffset: UIOffset? { get set }
要求
- iOS 10
- Xcode 10, Swift 5
许可协议
DDPerspectiveTransform
在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。