PinCodeInputView 1.0.0

PinCodeInputView 1.0.0

shima 维护。



  • shima

PinCodeInputView

一个用于输入PIN码的文本输入视图。

特性

  • 某些...

入门

视图层次

SurfaceView 用于检测用户手势。ItemView 是外观。您可以自定义 ItemView。

private class ContainerItemView<T: UIView & ItemType>: UIView {
    var itemView: T
    private let surfaceView: UIView = .init()
    private var didTapHandler: (() -> ())?
}

要创建自定义的 ItemView,您需要创建一个符合 ItemType 协议的视图。

public protocol ItemType {
    var text: Character? { get set }
    var isHiddenCursor: Bool { get set }
    func set(appearance: Appearance)
}

设置外观过程中。

public struct Appearance { }

pinCodeInputView.set(appearance: )

用法

import PinCodeInputView

常规

// initialize
let pinCodeInputView: PinCodeInputView<ItemView> = .init(
    digit: 6,
    itemSpacing: 8,
    itemFactory: {
    return ItemView()
})

view.addSubview(pinCodeInputView)

// set appearance
pinCodeInputView.set(
    appearance: .init(
        itemSize: .init(width: 44, height: 68),
        font: .systemFont(ofSize: 28, weight: .bold),
        textColor: .white,
        backgroundColor: .darkGray,
        cursorColor: .blue,
        cornerRadius: 8
    )
)

// text handling
pinCodeInputView.set(changeTextHandler: { text in
    print(text)
})

自定义

final class CustomItemView: UIView, ItemType {
    var text: Character?
    var isHiddenCursor: Bool
    func set(appearance: Appearance) {}
    
    // ...
}

let pinCodeInputView: PinCodeInputView<CustomItemView> = .init(
    digit: 6,
    itemSpacing: 8,
    itemFactory: {
    return CustomItemView()
})

安装

Carthage

使用Carthage安装,并将其添加到您的Cartfile中。

github "shima11/PinCodeInputView"
$ carthage update

CocoaPods

使用CocoaPods安装,并将其添加到您的Podfile中。

pod "PinCodeInputView"
$ pod update

授权

授权 MIT