TKInsertCodeView is a practical and customizable code insert UIView.
To run the example project, clone the repo and open TKInsertCodeView.xcodeproj
- Swift 3
- iOS 9.0 or higher
TKInsertCodeView is available through Tokenlab's TKPodSpec. To install it, simply add the following lines to your Podfile:
pod 'TKInsertCodeView', :git => 'https://github.com/tokenlab/TKInsertCodeView.git'
Simply add the following lines to your Cartfile:
github 'tokenlab/TKInsertCodeView'
You may easily customize through Interface Builder:
Property | Type | Default value | Description |
---|---|---|---|
secretCode |
Bool |
false | Hide/show inserted code |
numberOfFields |
Int |
4 | Number of code fields |
spacing |
CGFloat |
10 | Space between code fields |
cornerRadius |
CGFloat |
7.0 | Code field border |
borderWidth |
CGFloat |
10 | Code field border width |
fontName |
String |
Helvetica | Code font |
fontSize |
CGFloat |
17 | Code font size |
textColor |
UIColor |
#686868 (gray) | Code text color |
backgroundFieldColor |
UIColor |
#F1F1F1 (gray) | Code field background color |
borderColor |
UIColor |
#CBCBCB (gray) | Code field border color |
selecBackgroundColorField |
UIColor |
#F1F1F1 (gray) | Selected code field background color |
selecBorderColor |
CGFloat |
#007AFF (blue) | Selected code field border color |
invalidBackgroundColorField |
UIColor |
#F1F1F1 (gray) | Invalid code field background color |
invalidBorderColor |
CGFloat |
#007AFF (blue) | Invalid code field border color |
Or if you want to, you can implement TKCodeFieldViewProtocol
and use your own UIView
for code fields:
protocol TKCodeFieldViewProtocol: class {
var code: String? {get set}
func setSelected(_ selected: Bool)
}
To apply your customized view:
insertCodeView.codeFieldView = CustomCodeFieldView.init
To clear or insert a code:
insertCodeView.code = ""
To shake view:
insertCodeView.shake()
To present invalidate layout:
insertCodeView.invalidate()
To display normal layout:
insertCodeView.validate()
To programmatically keyboard up:
insertCodeView.setBecomeFirstResponder()
To programmatically keyboard down:
insertCodeView.setResignFirstResponder()
There are two optional functions.
When a code field was changed, this one is called:
func tkInsertCodeView(_ tkInsertCodeView: TKInsertCodeView, didChangeCode code: String)
When all code fields were fully:
func tkInsertCodeView(_ tkInsertCodeView: TKInsertCodeView, didFinishWritingCode code: String)
damboscolo, danielehidalgo@gmail.com
leosampaio, leo.sampaio.ferraz.ribeiro@gmail.com
TKInsertCodeView is available under the MIT license. See the LICENSE file for more info.