MKInputBoxView 是一个用来替换 UIAlertView 的类。基本上是 Swift 编写的 BMInputBox 的 Objective-C 版本。
内置 Objective-C,针对 iOS 8.0 及更高版本。支持 ARC。适用于 iPhone 和 iPad。
MKInputBoxView *inputBoxView = [MKInputBoxView boxOfType:NumberInput];
[inputBoxView show];
可用样式
PlainTextInput
- 简单文本字段NumberInput
- 仅接受数字的文本字段 - 数字键盘PhoneNumberInput
- 仅接受数字的文本字段 - 电话键盘EmailInput
- 仅接受电子邮件地址的文本字段 - 邮件键盘SecureTextInput
- 密码安全文本字段LoginAndPasswordInput
- 两个文本字段,用于用户名和密码输入更改模糊效果(UIBlurEffectStyle: 非常淡,淡,深)。
[inputBoxView setBlurEffectStyle:UIBlurEffectStyleDark];
设置标题和消息。
[inputBoxView setTitle:@"Who are you?"];
[inputBoxView setMessage:@"Please enter your username and password to get access to the system."];
设置按钮文本
[inputBoxView setSubmitButtonText:@"OK"];
[inputBoxView setCancelButtonText:@"Cancel"];
NumberInput
类型的小数。默认为 0。如果设置,则用户输入将被转换为带有两位小数的 Double。
[inputBoxView setNumberOfDecimals:2];
轻松操作 textField 的属性。
inputBoxView.customise = ^(UITextField *textField) {
textField.placeholder = @"Your eMail address";
if (textField.secureTextEntry) {
textField.placeholder = @"Your password";
}
textField.textColor = [UIColor whiteColor];
textField.layer.cornerRadius = 4.0f;
return textField;
};
inputBoxView.onSubmit = ^(NSString *value1, NSString *value2) {
NSLog(@"user: %@", value1);
NSLog(@"pass: %@", value2);
};
inputBoxView.onCancel = ^{
NSLog(@"Cancel!");
};