修复了密码登录的无法输入很长

This commit is contained in:
fengshuo
2023-01-17 15:41:59 +08:00
parent 47a6fa5262
commit 5874beb3af
4 changed files with 8 additions and 3 deletions

View File

@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic,copy) NSString *placeHolder; @property (nonatomic,copy) NSString *placeHolder;
///显示前面的文字 ///显示前面的文字
@property (nonatomic,copy) NSString *title; @property (nonatomic,copy) NSString *title;
///最大的长度
@property (nonatomic,assign) NSInteger maxLength;
@end @end

View File

@@ -71,7 +71,7 @@
_stackView = [[UIStackView alloc] init]; _stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal; _stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill; _stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter; _stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 0; _stackView.spacing = 0;
} }
return _stackView; return _stackView;
@@ -103,11 +103,11 @@
} }
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return textField.text.length <= 11; return textField.text.length <= self.maxLength;
} }
- (void)textFieldDidChangeSelection:(UITextField *)textField { - (void)textFieldDidChangeSelection:(UITextField *)textField {
textField.text = [textField.text substringToIndex:MIN(textField.text.length, 11)]; textField.text = [textField.text substringToIndex:MIN(textField.text.length, self.maxLength)];
} }
@end @end

View File

@@ -213,6 +213,7 @@
_phoneView.layer.masksToBounds = YES; _phoneView.layer.masksToBounds = YES;
_phoneView.layer.cornerRadius = 45/2; _phoneView.layer.cornerRadius = 45/2;
_phoneView.title = @"+86"; _phoneView.title = @"+86";
_phoneView.maxLength = 11;
if (@available(iOS 10.0, *)) { if (@available(iOS 10.0, *)) {
_phoneView.textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad; _phoneView.textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
} else { } else {
@@ -230,6 +231,7 @@
_codeView.layer.masksToBounds = YES; _codeView.layer.masksToBounds = YES;
_codeView.layer.cornerRadius = 45/2; _codeView.layer.cornerRadius = 45/2;
_codeView.title = @"密码"; _codeView.title = @"密码";
_codeView.maxLength = 16;
_codeView.textField.keyboardType = UIKeyboardTypeASCIICapable; _codeView.textField.keyboardType = UIKeyboardTypeASCIICapable;
_codeView.textField.secureTextEntry = YES; _codeView.textField.secureTextEntry = YES;
_codeView.textField.clearButtonMode = UITextFieldViewModeAlways; _codeView.textField.clearButtonMode = UITextFieldViewModeAlways;

View File

@@ -170,6 +170,7 @@
_phoneView.backgroundColor = [ThemeColor appCellBackgroundColor]; _phoneView.backgroundColor = [ThemeColor appCellBackgroundColor];
_phoneView.layer.masksToBounds = YES; _phoneView.layer.masksToBounds = YES;
_phoneView.layer.cornerRadius = 45/2; _phoneView.layer.cornerRadius = 45/2;
_phoneView.maxLength = 11;
} }
return _phoneView; return _phoneView;
} }