SGCodeTextField 0.1.4

SGCodeTextField 0.1.4

Sergiu Grigoriev 维护。




SGCodeTextField

适用于 iOS 和 tvOS 的简单 PIN 码文本框。可以通过 Interface Builder 或代码进行自定义。

Wiki

安装

通过 CocoaPods

pod "SGCodeTextField"

通过 SwiftPackageManager

dependencies: [
    .package(url: "https://github.com/grigorievs/SGCodeTextField.git", .upToNextMajor(from: "0.1.3"))
]

可自定义属性

  • count
  • placeholder
  • autocapitalization
  • font
  • digitCornerRadius
  • digitBackgroundColor
  • digitBackgroundColorFocused
  • digitBackgroundColorEmpty
  • digitBorderColor
  • digitBorderColorFocused
  • digitBorderColorEmpty
  • digitBorderWidth
  • digitSpacing
  • textColor
  • textColorFocused
  • placeholderColor
  • keyboardType

通过代码进行自定义

self.codeTextField.count = 4

self.codeTextField.placeholder = "*"

self.codeTextField.textColorFocused = UIColor.brown

self.codeTextField.refreshUI()

使用方法

接口构建器

Drag and drop a 'UIView' on to the desired view and change class to 'SGCodeTextField'.

代码

let codeTextField = SGCodeTextField()

获取文本

import SGCodeTextField

let value = self.codeTextField.text

设置文本

self.codeTextField.text = "1234"

观察文本更改事件

self.codeTextField.textChangeHandler = { text, completed in

    self.doneButton.isSelected = completed

    print(text ?? "")

}

屏幕截图

Editing mode

Default mode

其他自定义

Editing mode