|
|
@@ -11,11 +11,11 @@
|
|
|
#import <GRPCClient/GRPCCall+Tests.h>
|
|
|
#import <UU_Ent/Account.pbrpc.h>
|
|
|
|
|
|
-@interface YRLoginVC ()
|
|
|
+@interface YRLoginVC ()<UITextFieldDelegate>
|
|
|
+@property (nonatomic,strong) UIScrollView *scrollView;
|
|
|
@property (nonatomic,strong) UITextField *passwordTF;
|
|
|
@property (nonatomic,strong) UITextField *phoneTF;
|
|
|
-@property (nonatomic,strong) UIButton *loginBtn;
|
|
|
-@property (nonatomic,strong) UIButton *registerBtn;
|
|
|
+@property (nonatomic,strong) YRButton *loginBtn;
|
|
|
@property (nonatomic,strong) UIImageView *headImageV;
|
|
|
|
|
|
@end
|
|
|
@@ -27,4 +27,205 @@
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+#pragma mark --- 登录操作
|
|
|
+-(void)loginAction
|
|
|
+{
|
|
|
+ [GRPCCall useInsecureConnectionsForHost:kHostAddress];
|
|
|
+
|
|
|
+ AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
|
|
|
+
|
|
|
+ AccountSigninRequest *request = [AccountSigninRequest message];
|
|
|
+
|
|
|
+ DeviceInfo *model = [DeviceInfo new];
|
|
|
+
|
|
|
+ model.os = DeviceInfo_OS_Ios;
|
|
|
+
|
|
|
+ request.deviceInfo = model;
|
|
|
+
|
|
|
+ request.mobile = _phoneTF.text;
|
|
|
+
|
|
|
+ request.password = _passwordTF.text;
|
|
|
+
|
|
|
+ [client signinWithRequest:request handler:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
+
|
|
|
+ self.completed(YES);
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- UITextField Delegate
|
|
|
+- (BOOL)textFieldShouldReturn:(UITextField *)textField
|
|
|
+{
|
|
|
+ [self.view endEditing:YES];
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
|
|
+{
|
|
|
+ if ([string isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
|
|
|
+ //在这里做你响应return键的代码
|
|
|
+ [textField resignFirstResponder];
|
|
|
+ return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *allText = [textField.text stringByReplacingCharactersInRange:range withString:string];
|
|
|
+
|
|
|
+ [self changeRegisterBtn:allText and:textField];
|
|
|
+
|
|
|
+
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+-(BOOL)textFieldShouldClear:(UITextField *)textField
|
|
|
+{
|
|
|
+ _loginBtn.enabled = NO;
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)changeRegisterBtn:(NSString *)text and:(UITextField *)textField
|
|
|
+{
|
|
|
+ if (textField == _phoneTF) {
|
|
|
+ if (_passwordTF.text.length!=0 && text.length!=0) {
|
|
|
+ _loginBtn.enabled = YES;
|
|
|
+ }else
|
|
|
+ _loginBtn.enabled = NO;
|
|
|
+ }
|
|
|
+ if (textField == _passwordTF) {
|
|
|
+ if (_phoneTF.text.length!=0 && text.length!=0) {
|
|
|
+ _loginBtn.enabled = YES;
|
|
|
+ }else
|
|
|
+ _loginBtn.enabled = NO;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 注意:事件类型是:`UIControlEventEditingChanged`
|
|
|
+-(void)passConTextChange:(id)sender{
|
|
|
+// UITextField* target = (UITextField*)sender;
|
|
|
+// if (target.text.length == 11) {
|
|
|
+// if ([target.text isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_LoginName]]) {
|
|
|
+// [g_server getHeadImageSmall:g_server.myself.userId imageView:_headImage];
|
|
|
+// }else{
|
|
|
+// _headImage.image = [UIImage imageNamed:@"UU_newPublicPic"];
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// _headImage.image = [UIImage imageNamed:@"UU_newPublicPic"];
|
|
|
+// }
|
|
|
+}
|
|
|
+
|
|
|
+-(void)pwdTextChanged:(id)sender {
|
|
|
+ UITextField* target = (UITextField*)sender;
|
|
|
+
|
|
|
+ [self changeRegisterBtn:target.text and:target];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- 设置UI
|
|
|
+-(void)setUpUI
|
|
|
+{
|
|
|
+ [self.view addSubview:self.scrollView];
|
|
|
+ [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.left.right.equalTo(self.view);
|
|
|
+ make.width.mas_equalTo(self_width);
|
|
|
+ make.height.mas_equalTo(self_height);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UIImageView *bgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
|
|
|
+ bgView.image = [UIImage imageNamed:@"UU_newpg5-log in"];
|
|
|
+ [self.scrollView addSubview:bgView];
|
|
|
+
|
|
|
+ [self.scrollView addSubview:self.headImageV];
|
|
|
+
|
|
|
+ UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.headImageV.frame)+50, self_width, 50)];
|
|
|
+ firstView.backgroundColor = [UIColor clearColor];
|
|
|
+ [self.scrollView addSubview:firstView];
|
|
|
+
|
|
|
+ UIView *secondView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(firstView.frame)+2, self_width, 50)];
|
|
|
+ secondView.backgroundColor = [UIColor clearColor];
|
|
|
+ [self.scrollView addSubview:secondView];
|
|
|
+
|
|
|
+ UIImageView *account = [[UIImageView alloc]initWithFrame:CGRectMake(31, 15, 20, 20)];
|
|
|
+ account.image = [UIImage imageNamed:@"UU_newLoginAccount"];
|
|
|
+ [firstView addSubview:account];
|
|
|
+
|
|
|
+ UIImageView *password = [[UIImageView alloc]initWithFrame:CGRectMake(31, 15, 20, 20)];
|
|
|
+ password.image = [UIImage imageNamed:@"UU_newLoginPassword"];
|
|
|
+ [secondView addSubview:password];
|
|
|
+
|
|
|
+ UIImageView *line1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 48, self_width-40, 2)];
|
|
|
+ line1.backgroundColor = HexColor(@"#939393");
|
|
|
+ [firstView addSubview:line1];
|
|
|
+
|
|
|
+ UIImageView *line2 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 48, self_width-40, 2)];
|
|
|
+ line2.backgroundColor = HexColor(@"#939393");
|
|
|
+ [secondView addSubview:line2];
|
|
|
+
|
|
|
+ _phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(account.frame)+14, 0, self_width-90, 50)];
|
|
|
+ _phoneTF.delegate = self;
|
|
|
+ _phoneTF.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
+ _phoneTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
|
|
+ _phoneTF.enablesReturnKeyAutomatically = YES;
|
|
|
+ _phoneTF.returnKeyType = UIReturnKeyDone;
|
|
|
+ UIButton *button1 = [_phoneTF valueForKey:@"_clearButton"];
|
|
|
+ [button1 setImage:[UIImage imageNamed:@"UU_newDELETE"] forState:UIControlStateNormal];
|
|
|
+ _phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
|
+ _phoneTF.placeholder = @"登录";
|
|
|
+ _phoneTF.userInteractionEnabled = YES;
|
|
|
+ _phoneTF.backgroundColor = [UIColor clearColor];
|
|
|
+ _phoneTF.textColor = HexColor(@"#FFFFFF");
|
|
|
+ _phoneTF.keyboardType = UIKeyboardTypeNumberPad;
|
|
|
+ _phoneTF.font = [UIFont systemFontOfSize:18];
|
|
|
+ [_phoneTF setValue:HexColor(@"#FFFFFF") forKeyPath:@"_placeholderLabel.textColor"];
|
|
|
+ [firstView addSubview:_phoneTF];
|
|
|
+ [_phoneTF addTarget:self action:@selector(passConTextChange:) forControlEvents:UIControlEventEditingChanged];
|
|
|
+ _phoneTF.text = @"15018524229";
|
|
|
+
|
|
|
+ _passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(password.frame)+14, 0, self_width-90, 50)];
|
|
|
+ _passwordTF.delegate = self;
|
|
|
+ _passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
+ _passwordTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
|
|
+ _passwordTF.enablesReturnKeyAutomatically = YES;
|
|
|
+ _passwordTF.returnKeyType = UIReturnKeyDone;
|
|
|
+ UIButton *button2 = [_passwordTF valueForKey:@"_clearButton"];
|
|
|
+ [button2 setImage:[UIImage imageNamed:@"UU_newDELETE"] forState:UIControlStateNormal];
|
|
|
+ _passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
|
|
|
+ _passwordTF.placeholder = @"密码";
|
|
|
+ _passwordTF.secureTextEntry = YES;
|
|
|
+ _passwordTF.userInteractionEnabled = YES;
|
|
|
+ _passwordTF.backgroundColor = [UIColor clearColor];
|
|
|
+ _passwordTF.textColor = HexColor(@"#FFFFFF");
|
|
|
+ _passwordTF.font = [UIFont systemFontOfSize:18];
|
|
|
+ [_passwordTF setValue:HexColor(@"#FFFFFF") forKeyPath:@"_placeholderLabel.textColor"];
|
|
|
+ [secondView addSubview:_passwordTF];
|
|
|
+ [_passwordTF addTarget:self action:@selector(pwdTextChanged:) forControlEvents:UIControlEventAllEditingEvents|UIControlEventValueChanged];
|
|
|
+ _passwordTF.text = @"111111";
|
|
|
+
|
|
|
+ self.loginBtn = [[YRButton alloc]initWithTitle:@"登录" titleColor:nil titleFont:18 buttonNormalColor:nil buttonSelectColor:nil buttonDiabledColor:nil];
|
|
|
+ self.loginBtn.frame = CGRectMake(20, CGRectGetMaxY(secondView.frame)+25, self_width-40, 40);
|
|
|
+ [self.scrollView addSubview:self.loginBtn];
|
|
|
+ [self.loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- lazy
|
|
|
+-(UIScrollView *)scrollView{
|
|
|
+ if (!_scrollView) {
|
|
|
+ _scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
|
|
|
+ _scrollView.backgroundColor = [UIColor redColor];
|
|
|
+ }
|
|
|
+ return _scrollView;
|
|
|
+}
|
|
|
+
|
|
|
+-(UIImageView *)headImageV
|
|
|
+{
|
|
|
+ if (!_headImageV) {
|
|
|
+ _headImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
|
|
|
+ _headImageV.layer.masksToBounds = YES;
|
|
|
+ _headImageV.layer.cornerRadius = 35;
|
|
|
+ _headImageV.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
|
+ _headImageV.layer.borderWidth = 3;
|
|
|
+ _headImageV.center = CGPointMake(self_width/2, 81);
|
|
|
+ }
|
|
|
+ return _headImageV;
|
|
|
+}
|
|
|
+
|
|
|
@end
|