GDTextSlot
一个可定制的代码/文本输入控件。通过 Storyboard 和属性检查器或代码轻松设置。
要求
- Xcode 9+
- Swift 5
- iOS 9+
安装
手动安装
将 GDTextSlot.swift
拖放到您的项目中!
使用 CocoaPods
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'GDTextSlot'
end
pod install
使用方法
代码
let frame = CGRect(x: 0, y: 0, width: 300, height: 60)
let slotView = GDTextSlot(frame: frame)
slotView.delegate = self
view.addSubview(slotView)
设置属性
// Automatically activate text slot and show keyboard
// Or it will be activated when it's tapped
slotView.becomeFirstResponder()
// Set keyboard type -- Default is .numberPad
slotView.keyboard = .default
// Set number of slots -- Default is 4
slotView.numberOfSlots = 6
// Set space between slots -- Default is 50
slotView.baseWidth = 40
// Set text slot placeholder. Default is ___
slotView.placeholder = *
// Set custom font for the text
slotView.textFont = UIFont
遵循 GDTextSlotDelegate
func onTextEntered(_ slotView: GDTextSlot, _ finalText: String){
print(finalText)
}
故事板
- 添加一个
UIView
并将其自定义类设置为GDTextSlot
- 使用
Attributes 检查器
设置属性
运行!