From 5874beb3afd2108832dc1c9c03b4c39b1fd9c2ec Mon Sep 17 00:00:00 2001 From: fengshuo <963787902@qq.com> Date: Tue, 17 Jan 2023 15:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9A=84=E6=97=A0=E6=B3=95=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=BE=88=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xplan-ios/Main/Login/View/CustomView/LoginInputView.h | 2 ++ xplan-ios/Main/Login/View/CustomView/LoginInputView.m | 6 +++--- xplan-ios/Main/Login/View/LoginPasswordViewController.m | 2 ++ xplan-ios/Main/Login/View/LoginPhoneViewController.m | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/xplan-ios/Main/Login/View/CustomView/LoginInputView.h b/xplan-ios/Main/Login/View/CustomView/LoginInputView.h index 53a0e716..28d35884 100644 --- a/xplan-ios/Main/Login/View/CustomView/LoginInputView.h +++ b/xplan-ios/Main/Login/View/CustomView/LoginInputView.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic,copy) NSString *placeHolder; ///显示前面的文字 @property (nonatomic,copy) NSString *title; +///最大的长度 +@property (nonatomic,assign) NSInteger maxLength; @end diff --git a/xplan-ios/Main/Login/View/CustomView/LoginInputView.m b/xplan-ios/Main/Login/View/CustomView/LoginInputView.m index 27c082ce..4523a48c 100644 --- a/xplan-ios/Main/Login/View/CustomView/LoginInputView.m +++ b/xplan-ios/Main/Login/View/CustomView/LoginInputView.m @@ -71,7 +71,7 @@ _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisHorizontal; _stackView.distribution = UIStackViewDistributionFill; - _stackView.alignment = UIStackViewAlignmentCenter; + _stackView.alignment = UIStackViewAlignmentFill; _stackView.spacing = 0; } return _stackView; @@ -103,11 +103,11 @@ } - (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 { - textField.text = [textField.text substringToIndex:MIN(textField.text.length, 11)]; + textField.text = [textField.text substringToIndex:MIN(textField.text.length, self.maxLength)]; } @end diff --git a/xplan-ios/Main/Login/View/LoginPasswordViewController.m b/xplan-ios/Main/Login/View/LoginPasswordViewController.m index 6e6c094a..10bb3f23 100644 --- a/xplan-ios/Main/Login/View/LoginPasswordViewController.m +++ b/xplan-ios/Main/Login/View/LoginPasswordViewController.m @@ -213,6 +213,7 @@ _phoneView.layer.masksToBounds = YES; _phoneView.layer.cornerRadius = 45/2; _phoneView.title = @"+86"; + _phoneView.maxLength = 11; if (@available(iOS 10.0, *)) { _phoneView.textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad; } else { @@ -230,6 +231,7 @@ _codeView.layer.masksToBounds = YES; _codeView.layer.cornerRadius = 45/2; _codeView.title = @"密码"; + _codeView.maxLength = 16; _codeView.textField.keyboardType = UIKeyboardTypeASCIICapable; _codeView.textField.secureTextEntry = YES; _codeView.textField.clearButtonMode = UITextFieldViewModeAlways; diff --git a/xplan-ios/Main/Login/View/LoginPhoneViewController.m b/xplan-ios/Main/Login/View/LoginPhoneViewController.m index af8aa5ba..fba3de5c 100644 --- a/xplan-ios/Main/Login/View/LoginPhoneViewController.m +++ b/xplan-ios/Main/Login/View/LoginPhoneViewController.m @@ -170,6 +170,7 @@ _phoneView.backgroundColor = [ThemeColor appCellBackgroundColor]; _phoneView.layer.masksToBounds = YES; _phoneView.layer.cornerRadius = 45/2; + _phoneView.maxLength = 11; } return _phoneView; }