iOS 指定长度字符串填充整个TextField
iOS实现指定长度字符串占满整个TextField,支持支付宝和微信密码输入样式。## 实例
## 实现思路
采用两个TextField,一个只负责显示,重写它的drawText方法;
另一个只负责输入,设置它的字体颜色透明。
采用两个TextField实现的原因是iOS中重写`func drawText(in rect: CGRect)`函数,光标并不会相应的改变位置。所以我把UITextField自己的光标设置成透明,用UIView自己实现了一个光标。
## Requirements
Swift 4.2+
Xcode 10.1+
## Installation
Cocoapods is developing, you can drag the `LLimitTextField` folder into your project.
## Usage(代码实例)
```objectivec
//if auto insert space
limitTextField.isAutoInsertSpace = true
//auto insert space step
limitTextField.insertSpaceStep = 4
//Color of text
limitTextField.textColor = UIColor.black
limitTextField.font = UIFont.systemFont(ofSize: 25)
//the color of cursor
limitTextField.cursorColor = UIColor.black
limitTextField.keyboardType = .numberPad
//LLimitTextFieldDelegate
limitTextField.delegate = self
//under line type
limitTextField.underlineType = .one
//under line color
limitTextField.underlineColor = UIColor.cyan
//Max limit
limitTextField.limitLength = 16
```
## UnderLine/SeperatorLine Type(分割线类型)
```cpp
enum TextFieldUnderlineType{
//no underline
case none
//one line
case one
//Underline each character below
case spaced
//Gridlines
case grid
}
```
页:
[1]