123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- //
- // UserLoginAccountViewController.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/29.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "UserLoginAccountViewController.h"
- #import "UserRegisterAccountViewController.h"
- #import "NSBundle+KODLocalizable.h"
- #import "KODCommonConst.h"
- @interface UserLoginAccountViewController () <UITextFieldDelegate>
- @property(nonatomic,strong)UIView *listView;
- @end
- @implementation UserLoginAccountViewController
- -(void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
-
- self.accountTextField.textColor = [UIColor blackColor];
- self.passwordTextField.textColor = [UIColor blackColor];
-
- //默认账号填充
- XSUser *user = XSUser.history.firstObject;
- self.accountTextField.text = user.userName;
-
- }
- -(void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
-
- [self.listView removeFromSuperview];
- self.listView = nil;
-
- }
- - (IBAction)PullAccoutList:(UIButton *)sender {
- sender.selected = !sender.selected;
-
- if (sender.selected) {
- NSInteger count = XSUser.history.count;
- if (count >4) {
- count = 4;
- }
- [self setAccoutListWith:count];
- }else{
- [self.listView removeFromSuperview];
- }
- }
- -(void)setAccoutListWith:(NSInteger)count {
-
- if (count == 0) {
- return;
- }
-
- if (self.listView) {
- [self.listView removeFromSuperview];
- }
-
- self.listView = [[UIView alloc]init];
- self.listView.frame = CGRectMake(self.accountInputView.frame.origin.x, self.accountInputView.frame.origin.y +self.accountInputView.frame.size.height*+1+3, self.accountInputView.frame.size.width, self.accountInputView.frame.size.height*count-(count-1)*1);
- self.listView.backgroundColor = [UIColor whiteColor];
- self.listView.userInteractionEnabled = YES;
- [self.view addSubview:self.listView];
-
- for (int i=0; i<count; i++) {
-
- //XSUser *user = [XSUser.history objectAtIndex:i];
- XSUser *user = XSUser.history.firstObject;
-
-
-
- UIView *v1 = [[UIView alloc]init];
- v1.backgroundColor = [UIColor whiteColor];
- v1.frame = CGRectMake(0, self.accountInputView.frame.size.height*i-i*1, self.accountInputView.frame.size.width, self.accountInputView.frame.size.height);
- v1.userInteractionEnabled = YES;
- v1.backgroundColor = [UIColor whiteColor];
- v1.layer.borderWidth =1;
- v1.layer.borderColor = [[UIColor.lightGrayColor colorWithAlphaComponent:0.8] CGColor];
- UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(CGFloatBasedI375(5), CGFloatBasedI375(7), CGFloatBasedI375(26), CGFloatBasedI375(26))];
- UIImage* image = [UIImage imageNamed:@"login_pwd_btn_bg" inBundle:XenonSDK.sharedSDK.bundle compatibleWithTraitCollection:nil];
- imgView.image = image;
- v1.tag = 100+i;
- [v1 addSubview:imgView];
- UILabel *label = [[UILabel alloc]init];
- label.frame = CGRectMake(CGFloatBasedI375(34), 0, v1.frame.size.width-CGFloatBasedI375(34), 40);
- label.font = [UIFont systemFontOfSize:14];
- label.adjustsFontSizeToFitWidth = YES;
- label.textColor = [UIColor blackColor];
- label.textAlignment = NSTextAlignmentLeft;
- label.text = user.userName;
- label.tag = 200+i;
- label.userInteractionEnabled = YES;
- [v1 addSubview:label];
- UITapGestureRecognizer *taper = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideClickedView:)];
- [v1 addGestureRecognizer:taper];
- [self.listView addSubview:v1];
-
- }
- }
- -(void)hideClickedView:(UITapGestureRecognizer *)taper {
- [self.listView removeFromSuperview];
- UIView *v1 = (UIView *)taper.view;
- NSInteger index = v1.tag;
- UILabel *label = [v1 viewWithTag:index+100];
- self.accountTextField.text = label.text;
-
- }
- - (void)loginForPassword:(id)sender {
- // Resign editing.
- [self.view endEditing:YES];
- // Must enter account.
- NSString* account = self.accountTextField.text;
- if (account.length == 0) {
- //请输入帐号
- NSString *str = [NSBundle KOD_localizedStringForKey:PleaseEnterAccount];
- [XSNetwork showHudFailure:str];
- return;
- }
- // Must enter password.
- NSString* password = self.passwordTextField.text;
- if (password.length == 0) {
- //请输入密码
- NSString *str = [NSBundle KOD_localizedStringForKey:PleaseEnterPwd];
- [XSNetwork showHudFailure:str];
- return;
- }
- [XSNetwork showHudLoading];
- [XSNetwork loginWithAccount:account password:password complete:^(id object, NSError *error) {
-
-
- if (error != nil) {
- [XSNetwork showHudFailure:error];
- return;
- }
-
- if (XenonSDK.sharedSDK.sdk_loginCallback) {
- XenonSDK.sharedSDK.sdk_loginCallback(object);
- }
- }];
- }
- - (void)displayModeForPassword:(UIButton*)sender {
- // Toggle password display mode.
- sender.selected = !sender.selected;
- self.passwordTextField.secureTextEntry = sender.selected;
- }
- //Register user account
- - (IBAction)sdk_showViewControllerForUserRegister2:(id)sender {
-
- [self.view endEditing:YES];
- [self.navigationController pushViewController:UserRegisterAccountViewController.new animated:YES];
-
- }
- // MARK: -
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
-
- if (textField.returnKeyType == UIReturnKeyDone) {
- [self loginForPassword:textField];
- return NO;
- }
-
- if (textField == self.accountTextField) {
- [self.passwordTextField becomeFirstResponder];
- }
-
- return YES;
- }
- @end
|