MGLoginView.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // MGLoginView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/7/16.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "MGLoginView.h"
  9. @implementation MGLoginView{
  10. UILabel *_titleL;
  11. UITextField *_phoneT;
  12. UITextField *_confirmT;
  13. UIButton *_confirmBtn;
  14. UIView *_line1;
  15. UIView *_line2;
  16. }
  17. - (instancetype)init
  18. {
  19. self = [super init];
  20. if (self) {
  21. [self setUpView];
  22. [self resetView];
  23. [self updateThirdLoginButton];
  24. }
  25. return self;
  26. }
  27. -(void)setUpView{
  28. self.bgImgView = [UIImageView new];
  29. self.bgImgView.image = [UIImage imageNamed:@"lg_new_bgImage"];
  30. [self addSubview:self.bgImgView];
  31. _titleL = [UILabel new];
  32. _titleL.font = [UIFont systemFontOfSize:17];
  33. _titleL.text = ASLocalizedString(@"手机号验证码登录");
  34. _titleL.textColor = [UIColor colorWithHexString:@"#CC45FF"];
  35. _phoneT = [UITextField new];
  36. _phoneT.font = [UIFont systemFontOfSize:15];
  37. _phoneT.placeholder = ASLocalizedString(@"请输入手机号");
  38. _phoneT.keyboardType = UIKeyboardTypeNumberPad;
  39. self.phoneText = _phoneT;
  40. _confirmT = [UITextField new];
  41. _confirmT.font = [UIFont systemFontOfSize:15];
  42. _confirmT.placeholder = ASLocalizedString(@"请输入验证码");
  43. _confirmT.keyboardType = UIKeyboardTypeNumberPad;
  44. _codeText = _confirmT;
  45. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  46. [_confirmBtn setTitle:ASLocalizedString(@"获取验证码")forState:UIControlStateNormal];
  47. _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  48. [_confirmBtn setTitleColor:[UIColor colorWithHexString:@"#CC45FF"] forState:UIControlStateNormal];
  49. [_confirmBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  50. [_confirmBtn setBackgroundImage:[UIImage imageNamed:@"mg_ig_CodeBtn"] forState:UIControlStateNormal];
  51. _confirmBtn.tag = 10;
  52. _codeBtn = _confirmBtn;
  53. _line1 = [UIView new];
  54. _line2 = [UIView new];
  55. _line1.backgroundColor = KMGLineColor;
  56. _line2.backgroundColor = KMGLineColor;
  57. self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  58. [self.loginBtn setTitle:ASLocalizedString(@"立即登录")forState:UIControlStateNormal];
  59. [self.loginBtn setBackgroundImage:[UIImage imageNamed:@"mg_ig_LoginBtn"] forState:UIControlStateNormal];
  60. [self.loginBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  61. self.loginBtn.tag = 11;
  62. self.wxLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  63. [self.wxLoginBtn setImage:[UIImage imageNamed:@"mg_ig_wxLoginBtn"] forState:UIControlStateNormal];
  64. [self.wxLoginBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  65. // self.wxLoginBtn.tag = 12;
  66. self.infoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  67. // self.infoBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  68. NSString *firstStr = ASLocalizedString(@"登录即代表同意");
  69. NSString *secondStr = ASLocalizedString(@"《用户隐私政策》");
  70. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@",firstStr,secondStr]];
  71. [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#646464"] range:NSMakeRange(0, firstStr.length)];
  72. [attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#FFAD00"] range:NSMakeRange(firstStr.length, secondStr.length)];
  73. self.infoBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  74. self.infoBtn.tag = 13;
  75. [self.infoBtn setAttributedTitle:attributeString forState:UIControlStateNormal];
  76. [self.infoBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  77. self.otherL = [UILabel new];
  78. self.otherL.text = ASLocalizedString(@"-----其他方式登录-----");
  79. self.otherL.font = [UIFont systemFontOfSize:14];
  80. self.otherL.textAlignment = NSTextAlignmentCenter;
  81. self.otherL.textColor = [UIColor colorWithHexString:@"#666666"];
  82. self.loginView = [UIView new];
  83. self.qqBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  84. [self.qqBtn setImage:[UIImage imageNamed:@"mg_login_qq"] forState:UIControlStateNormal];
  85. self.wxBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  86. [self.wxBtn setImage:[UIImage imageNamed:@"mg_login_wx"] forState:UIControlStateNormal];
  87. self.wxBtn.tag = 12;
  88. [self.wxBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  89. [self.loginView addSubview:self.qqBtn];
  90. [self.loginView addSubview:self.wxBtn];
  91. [self addSubview:_titleL];
  92. [self addSubview:_phoneT];
  93. [self addSubview:_confirmT];
  94. [self addSubview:_confirmBtn];
  95. [self addSubview:_line1];
  96. [self addSubview:_line2];
  97. [self addSubview:self.loginBtn];
  98. [self addSubview:self.wxLoginBtn];
  99. [self addSubview:self.infoBtn];
  100. [self addSubview:self.otherL];
  101. [self addSubview:self.loginView];
  102. }
  103. -(void)updateThirdLoginButton
  104. {
  105. __weak __typeof(self)weakSelf = self;
  106. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  107. [parmDict setObject:@"app" forKey:@"ctl"];
  108. [parmDict setObject:@"init" forKey:@"act"];
  109. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  110. if ([responseJson toInt:@"status"] == 1) {
  111. // [GlobalVariables sharedInstance].appModel.has_qq_login = 1;
  112. self.loginArr = [NSMutableArray array];
  113. if ([GlobalVariables sharedInstance].appModel.has_qq_login != 0) {
  114. [self.loginArr addObject:_qqBtn];
  115. }
  116. if ([GlobalVariables sharedInstance].appModel.has_wx_login != 0) {
  117. [self.loginArr addObject:_wxBtn];
  118. }
  119. self.loginView.frame = CGRectMake(0,self.otherL.bottom, kRealValue(335), kRealValue(50));
  120. self.loginView.width = self.loginArr.count *( 42 + 26);
  121. self.infoBtn.frame = CGRectMake(kRealValue(5), self.loginView.bottom + kRealValue(10), kRealValue(200), kRealValue(11));
  122. self.loginView.centerX = self.infoBtn.centerX = self.otherL.centerX = self.loginBtn.centerX = _line1.centerX;
  123. [self makeEqualWidthViews:self.loginArr inView:self.loginView LRpadding:5 viewPadding:0];
  124. }
  125. } FailureBlock:^(NSError *error) {
  126. // [weakSelf updateThirdLoginButton];
  127. }];
  128. }
  129. -(void)resetView{
  130. _titleL.frame = CGRectMake(kRealValue(10), kRealValue(28), kRealValue(200), kRealValue(20));
  131. _phoneT.frame = CGRectMake(kRealValue(10), _titleL.bottom + kRealValue(24), kRealValue(314), kRealValue(50));
  132. _line1.frame = CGRectMake(_phoneT.left, _phoneT.bottom, _phoneT.width, 1);
  133. _confirmT.frame = CGRectMake(kRealValue(10), _phoneT.bottom + kRealValue(25), kRealValue(220), kRealValue(50));
  134. _line2.frame = CGRectMake(_line1.left, _confirmT.bottom, _line1.width, 1);
  135. _confirmBtn.frame = CGRectMake(_confirmT.right, _confirmT.top, kRealValue(98), kRealValue(35));
  136. self.loginBtn.frame = CGRectMake(_line1.left - kRealValue(5), _line2.bottom + kRealValue(30), kRealValue(187) ,kRealValue(52));
  137. // self.wxLoginBtn.frame = CGRectMake(self.loginBtn.left, self.loginBtn.bottom + kRealValue(30), self.loginBtn.width, self.loginBtn.height);
  138. self.otherL.frame = CGRectMake(0, self.loginBtn.bottom + kRealValue(15), kRealValue(223), kRealValue(20));
  139. self.loginView.frame = CGRectMake(0,self.otherL.bottom, kRealValue(335), kRealValue(50));
  140. self.loginView.width = self.loginArr.count *( 42 + 26);
  141. self.infoBtn.frame = CGRectMake(kRealValue(5), self.loginView.bottom + kRealValue(10), kRealValue(200), kRealValue(11));
  142. self.loginView.centerX = self.infoBtn.centerX = self.otherL.centerX = self.loginBtn.centerX = _line1.centerX;
  143. }
  144. -(void)makeEqualWidthViews:(NSArray *)views inView:(UIView *)containerView LRpadding:(CGFloat)LRpadding viewPadding :(CGFloat)viewPadding
  145. {
  146. UIView *lastView;
  147. for (UIView *view in views) {
  148. [containerView addSubview:view];
  149. if (lastView) {
  150. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.top.bottom.equalTo(containerView);
  152. make.left.equalTo(lastView.mas_right).offset(viewPadding);
  153. make.width.equalTo(lastView);
  154. }];
  155. }else
  156. {
  157. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  158. make.left.equalTo(containerView).offset(LRpadding);
  159. make.top.bottom.equalTo(containerView);
  160. }];
  161. }
  162. lastView=view;
  163. }
  164. [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.right.equalTo(containerView).offset(-LRpadding);
  166. }];
  167. }
  168. -(void)btnClick:(UIButton *)sender{
  169. if (self.clickLoginBlock) {
  170. self.clickLoginBlock(sender.tag - 10);
  171. }
  172. }
  173. @end