测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最近发布 | 2015年11月 |
由 Marian Paul、Sébastien HOUZÉ、Lucas Ortis 维护。
依赖项 | |
PPHelpMe | ~> 1.0.2 |
VLRJVFloatLabeledTextField | ~> 1.0.3 |
VeryLastRoom iOS textField
这个类旨在为两个优秀的库在UITextField
上提供扩展功能
JVFloatLabeledTextField
,其目的是在文本框插入文本时,在上方优雅地显示占位符HTAutocompleteTextField
,其目的是提供自动完成功能(例如:电子邮件、公司名称等)VLRTextfield
增加了一个新的层面: 验证(例如,在表单中非常好用)。然后可以指定几个检查行为,如
regex
) AND/ORfillRequired
) AND/ORminimumNumberOfCharacters
) AND/ORvalidateBlock
).所有这些测试都可以在需要时或在编辑时运行。
VLRTextField *name = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter your first name"];
name.autocapitalizationType = UITextAutocapitalizationTypeWords;
name.formKeyPath = @"name";
name.messageRequired = @"Your first name is required";
static NSString *REGULAR_EXPRESSION_EMAIL = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}";
VLRTextField *email = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter an email to reach you"];
email.keyboardType = UIKeyboardTypeEmailAddress;
email.regex = REGULAR_EXPRESSION_EMAIL;
email.messageInvalid = @"Your email address is invalid";
email.messageRequired = @"Please enter an email adress";
email.formKeyPath = @"email_address";
email.autocompleteDataSource = [VLRAutoCompleteManager sharedManager];
email.autocompleteType = VLRAutocompleteTypeEmail;
注意:VLRAutoCompleteManager
。查看HTAutocompleteTextField
。
VLRTextField *password = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter a password"];
password.minimumNumberOfCharacters = 8;
password.messageRequired = @"The password should be 8 characters long";
password.formKeyPath = @"password_1";
password.secureTextEntry = YES;
我们使用该块来检查两个密码是否相同
VLRTextField *passwordConfirmation = [VLRTextField formTextFieldWithFrame:CGRectMake(kXOffset, kYOffset + CGRectGetMaxY(password.frame), width, kTextFieldHeight) placeholder:@"Re enter your password"];
passwordConfirmation.messageInvalid = @"The two passwords should match";
passwordConfirmation.messageRequired = @"Please re enter your password";
passwordConfirmation.minimumNumberOfCharacters = password.minimumNumberOfCharacters;
passwordConfirmation.formKeyPath = @"password_2";
passwordConfirmation.secureTextEntry = YES;
passwordConfirmation.validateBlock = ^BOOL(VLRTextField *textField) {
return [[password text] isEqualToString:textField.text];
};
VLRTextField *company = [VLRTextField formTextFieldWithFrame:CGRectMake(kXOffset, kYOffset + CGRectGetMaxY(passwordConfirmation.frame), width, kTextFieldHeight) placeholder:@"Enter the company you work for"];
company.fillRequired = NO;
company.formKeyPath = @"company_name";
company.autocompleteDataSource = [VLRAutoCompleteManager sharedManager];
company.autocompleteType = VLRAutoCompleteCompany;
company.autocapitalizationType = UITextAutocapitalizationTypeSentences;
company.returnKeyType = UIReturnKeyDone;
注意:VLRAutoCompleteManager
。查看HTAutocompleteTextField
。
除了验证用户输入的内容外,还可以使用VLRFormService
来
returnKeyType
` 等于 `UIReturnKeyNext
NSDictionary
如果有必要,可以子类化 VLRFormService
以添加符合您需求的新行为。
VLRFormService
self.registerTextFieldManager = [VLRFormService new];
// The order does matter (for next behavior)
[self.registerTextFieldManager addTextField:name];
[self.registerTextFieldManager addTextField:email];
[self.registerTextFieldManager addTextField:password];
[self.registerTextFieldManager addTextField:passwordConfirmation];
[self.registerTextFieldManager addTextField:company];
检查并显示错误
- (void) send {
BOOL formValid = [self.registerTextFieldManager checkForm]; // Will check and display errors
if (formValid) {
[self.registerTextFieldManager.activeField resignFirstResponder];
[self safelySend];
}
}
检查但不显示错误
BOOL formValid = [self.registerTextFieldManager checkFormAndShowErrors:NO];
这将使用 VLRTextField
上的 formKeyPath
属性
NSDictionary *json = [self.registerTextFieldManager extractFieldsAsJson];