| 测试已测试 | ✗ |
| Lang语言 | SwiftSwift |
| 许可证 | MIT |
| Released最新版本 | 2017年3月 |
| SwiftSwift 版本 | 3.0 |
| SPM支持 SPM | ✗ |
由 Adam Eri 维护。
BMInputBox 是一个用 Swift 编写的 iOS 插件类,用于显示输入框,用户可以通过该框输入不同类型的数据,例如用户名、密码、电子邮件地址、数字、纯文本文本。BMInputBox 用作替代有限 UIAlertView 输入选项的替代方案。
在 Swift 3 下编译,支持 iOS 8.0 及以上版本。所有设备都受支持。BMInputBox 既可以用于 Swift 也可以用于 Objective-C 项目。
版本 1.3.x 及以上需要 Xcode 8。版本 1.2.x 及以上需要 Xcode 7。
对于使用 Swift 2 的旧项目,请使用版本 1.2.x。对于使用 Swift 1.2 的旧项目,请使用版本 1.1.3。
将模块导入到您的项目中。
import BMInputBoxlet inputBox = BMInputBox.boxWithStyle(.NumberInput)
inputBox.show()可用样式
.plainTextInput - 简单文本字段.numberInput - 仅接受数字的文本字段 - 数字键盘.phoneNumberInput - 仅接受数字的文本字段 - 电话键盘.emailInput - 仅接受电子邮件地址的文本字段 - 电子邮件键盘.secureTextInput - 密码的加密文本字段.loginAndPasswordInput - 用户名和密码输入的两个文本字段UIBlurEffectStyle: .extraLight, .light, .dark
inputBox.blurEffectStyle = .light您可以为视图中所有组件设置自定义文本。有关验证部分也请参阅。
inputBox.title = NSLocalizedString("This Is The Title", comment: "")
inputBox.message = NSLocalizedString("This is the message in the view, can be as long as three lines.", comment: "")
inputBox.submitButtonText = NSLocalizedString("OK", comment: "")
inputBox.cancelButtonText = NSLocalizedString("Cancel", comment: "")
inputBox.validationLabelText = NSLocalizedString("Text must be 6 characters long.", comment: "")对于 .NumberInput 类型。默认值是 0。如果设置,则用户输入将转换成有 2 位小数的 Double。例如“1”变为“0.01”,而“1234”变为“12.34”。
inputBox.numberOfDecimals = 2在框中的textField中使用你需要的任何操作。
inputBox.customiseInputElement = {(element: UITextField) in
element.placeholder = "Custom placeholder"
if element.secureTextEntry == true {
element.placeholder = "Secure placeholder"
}
return element
}为 .NumberInput 类型设置最小值和最大值。在 textField 下方显示消息给用户。输入的值会与这些值进行验证。
设置最小值
inputBox.minimumValue = 10
inputBox.validationLabelText = "A number greater %@."设置最小值和最大值
inputBox.minimumValue = 10
inputBox.maximumValue = 30
inputBox.validationLabelText = "A number between %@ and %@."设置输入文本的最小值和最大长度。如果值相同,将检查确切的长度。
inputBox.minimumLenght = 4
inputBox.maximumLength = 6
inputBox.validationLabelText = "A text between %i and %i characters."当将框设置为 可选 时,将接受 nil 值。但是,如果输入了文本,它将再次根据上面的其他属性进行验证。
inputBox.isOptional = trueinputBox.onSubmit = {(value: AnyObject...) in
for text in value {
if text is String {
NSLog("%@", text as String)
}
else if text is NSDate {
NSLog("%@", text as NSDate)
}
else if text is Int {
NSLog("%i", text as Int)
}
}
}inputBox.onCancel = {
NSLog("Cancelled")
}Objective-C 中不支持元组,因此,如果您的项目是 Objective-C,则必须使用 onSubmitObjc 闭包。这将返回一个包含 Input Box 值的数组。
inputBox.onSubmitObjc = {(values: [AnyObject]) in
for text in values {
if text is String {
NSLog("%@", text as String)
}
else if text is NSDate {
NSLog("%@", text as NSDate)
}
else if text is Int {
NSLog("%i", text as Int)
}
}
}您可以在文本输入时与之交互。闭包绑定到 UITextField 的 .editingChanged 事件。
inputBox.onChange = {(value: String) in
return value.uppercaseString
}