InputViewForSMSCod.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // InputView.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2019/6/10.
  6. // Copyright © 2019 APPLE. All rights reserved.
  7. //
  8. #import "InputViewForSMSCod.h"
  9. #import "iPhone.h"
  10. @implementation InputViewForSMSCod
  11. @synthesize delegate;
  12. @synthesize phoneNumInput;
  13. @synthesize smsInput;
  14. @synthesize smsCodeBtn;
  15. @synthesize phoneErrorTipsLabel;
  16. @synthesize smsErrorTipsLabel;
  17. /*
  18. // Only override drawRect: if you perform custom drawing.
  19. // An empty implementation adversely affects performance during animation.
  20. - (void)drawRect:(CGRect)rect {
  21. // Drawing code
  22. }
  23. */
  24. - (id)initWithFrame:(CGRect)frame{
  25. self = [super initWithFrame:CGRectMake(0, 0, SCREEN_W, 44.f*3.f+2*30.f/2.f)];
  26. if (self){
  27. [self setBackgroundColor:[UIColor clearColor]];
  28. [self drawView];
  29. }
  30. return self;
  31. }
  32. - (void)drawView{
  33. CGFloat w_left_right = 37.f;
  34. /*电话号码输入框*/
  35. UIView *phoneNumInputBGView = [[UIView alloc] init];
  36. [phoneNumInputBGView.layer setCornerRadius:8.f/2.f];
  37. [phoneNumInputBGView setBackgroundColor:[UIColor clearColor]];
  38. /*电话号码输入框*/
  39. phoneNumInput = [[UITextField alloc] init];
  40. [phoneNumInput.layer setCornerRadius:8.f/2.f];
  41. [phoneNumInput setBackgroundColor:[UIColor clearColor]];
  42. NSString *placeholderStr = NSLocalizedString(@"log_phone_placeholderStr",nil);
  43. CGFloat fontSize = 14.f;
  44. CGFloat inputTextFieldH = 48.f;
  45. CGFloat inputTextFieldBGH = 68.f;
  46. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  47. style.alignment = NSTextAlignmentLeft;
  48. NSAttributedString *attri = nil;
  49. NSString *verphone = [iPhone phoneVersion];
  50. if ([verphone isEqualToString:@"10.3.3"]){
  51. attri = [[NSAttributedString alloc] initWithString:placeholderStr
  52. attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  53. NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  54. NSBaselineOffsetAttributeName:[NSNumber numberWithFloat:-1.5],
  55. NSParagraphStyleAttributeName:style}];
  56. }else{
  57. attri = [[NSAttributedString alloc] initWithString:placeholderStr
  58. attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  59. NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  60. NSParagraphStyleAttributeName:style}];
  61. }
  62. phoneNumInput.attributedPlaceholder = attri;
  63. [phoneNumInputBGView addSubview:phoneNumInput];
  64. [phoneNumInput mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(0.f);
  66. make.left.mas_equalTo(0);
  67. make.right.mas_equalTo(0);
  68. make.height.mas_equalTo(inputTextFieldH);
  69. }];
  70. [phoneNumInput setTextColor:HW0A132BColor];
  71. [phoneNumInput setClearButtonMode:(UITextFieldViewModeWhileEditing)];
  72. [phoneNumInput setKeyboardType:(UIKeyboardTypeNumberPad)];
  73. /*下划线*/
  74. UIView *line0 = [[UIView alloc] init];
  75. [line0 setBackgroundColor:HWC1C9D6Color];
  76. [phoneNumInputBGView addSubview:line0];
  77. [line0 mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.equalTo(phoneNumInput.mas_bottom);
  79. make.left.mas_equalTo(0.f);
  80. make.right.mas_equalTo(0);
  81. make.height.mas_equalTo(1.f);
  82. }];
  83. /*提示语*/
  84. phoneErrorTipsLabel = [[UILabel alloc] init];
  85. [phoneErrorTipsLabel setText:NSLocalizedString(@"log_phone_error_tips",nil)];
  86. [phoneErrorTipsLabel setFont:[UIFont systemFontOfSize:12]];
  87. [phoneErrorTipsLabel setTextColor:HWDD4E4EColor];
  88. [phoneNumInputBGView addSubview:phoneErrorTipsLabel];
  89. [phoneErrorTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.bottom.mas_equalTo(-2.f);
  91. make.left.mas_equalTo(0.f);
  92. make.right.mas_equalTo(0);
  93. }];
  94. [phoneErrorTipsLabel setHidden:YES];
  95. [self addSubview:phoneNumInputBGView];
  96. [phoneNumInputBGView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.mas_equalTo(0.f);
  98. make.left.mas_equalTo(w_left_right);
  99. make.right.mas_equalTo(-w_left_right);
  100. make.height.mas_equalTo(inputTextFieldBGH);
  101. }];
  102. /*验证码输入框 验证码获取按钮*/
  103. /*计算验证码输入框 宽度 获取验证码按钮宽度*/
  104. UIView *smsInputBGView = [[UIView alloc] init];
  105. [smsInputBGView.layer setCornerRadius:8.f/2.f];
  106. [smsInputBGView setBackgroundColor:[UIColor clearColor]];
  107. CGFloat w_smsBtn = 67.f;
  108. smsInput = [[UITextField alloc] init];
  109. [smsInput.layer setCornerRadius:8.f/2.f];
  110. [smsInput setBackgroundColor:[UIColor clearColor]];
  111. [smsInput setTextColor:HW0A132BColor];
  112. NSString *placeholderStrForSms = NSLocalizedString(@"log_sms_placeholderStr",nil);
  113. NSMutableParagraphStyle *style2 = [[NSMutableParagraphStyle alloc] init];
  114. style2.alignment = NSTextAlignmentLeft;
  115. NSAttributedString *attri2 = nil;
  116. if ([verphone isEqualToString:@"10.3.3"]){
  117. attri2 = [[NSAttributedString alloc] initWithString:placeholderStrForSms
  118. attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  119. NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  120. NSBaselineOffsetAttributeName:[NSNumber numberWithFloat:-1.5],
  121. NSParagraphStyleAttributeName:style2}];
  122. }else{
  123. attri2 = [[NSAttributedString alloc] initWithString:placeholderStrForSms
  124. attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  125. NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  126. NSParagraphStyleAttributeName:style2}];
  127. }
  128. smsInput.attributedPlaceholder = attri2;
  129. [smsInputBGView addSubview:smsInput];
  130. [smsInput mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.top.mas_equalTo(0);
  132. make.left.mas_equalTo(0);
  133. make.right.mas_equalTo(-w_smsBtn);
  134. make.height.mas_equalTo(inputTextFieldH);
  135. }];
  136. [smsInput setClearButtonMode:(UITextFieldViewModeWhileEditing)];
  137. [smsInput setKeyboardType:(UIKeyboardTypeNumberPad)];
  138. /*获取验证码按钮*/
  139. smsCodeBtn = [[UIButton alloc] init];
  140. [smsCodeBtn setBackgroundColor:[UIColor clearColor]];
  141. [smsCodeBtn setTitle:NSLocalizedString(@"log_sms_get",nil) forState:(UIControlStateNormal)];
  142. [smsCodeBtn.titleLabel setFont:[UIFont systemFontOfSize:13.f]];
  143. [smsCodeBtn setTitleColor:COLOR_HEIGHT_BTN forState:(UIControlStateNormal)];
  144. [smsCodeBtn setTitleColor:COLOR_UNABLE_TITLE_BTN forState:(UIControlStateDisabled)];
  145. [smsCodeBtn addTarget:self action:@selector(smsCodeBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  146. [smsCodeBtn.layer setCornerRadius:8.f/2.f];
  147. [smsInputBGView addSubview:smsCodeBtn];
  148. [smsCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.left.equalTo(self->smsInput.mas_right);
  150. make.top.equalTo(self->smsInput.mas_top);
  151. make.width.mas_equalTo(w_smsBtn);
  152. make.height.mas_equalTo(inputTextFieldH);
  153. }];
  154. /*下划线*/
  155. UIView *line1 = [[UIView alloc] init];
  156. [line1 setBackgroundColor:HWC1C9D6Color];
  157. [smsInputBGView addSubview:line1];
  158. [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
  159. make.top.equalTo(smsInput.mas_bottom);
  160. make.left.mas_equalTo(0.f);
  161. make.right.mas_equalTo(0);
  162. make.height.mas_equalTo(1.f);
  163. }];
  164. /*提示语*/
  165. smsErrorTipsLabel = [[UILabel alloc] init];
  166. [smsErrorTipsLabel setText:NSLocalizedString(@"log_sms_error_tips",nil)];
  167. [smsErrorTipsLabel setFont:[UIFont systemFontOfSize:12]];
  168. [smsErrorTipsLabel setTextColor:HWDD4E4EColor];
  169. [smsInputBGView addSubview:smsErrorTipsLabel];
  170. [smsErrorTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.bottom.mas_equalTo(-2.f);
  172. make.left.mas_equalTo(0.f);
  173. make.right.mas_equalTo(0);
  174. }];
  175. [smsErrorTipsLabel setHidden:YES];
  176. [self addSubview:smsInputBGView];
  177. [smsInputBGView mas_makeConstraints:^(MASConstraintMaker *make) {
  178. make.top.equalTo(phoneNumInputBGView.mas_bottom);
  179. make.left.mas_equalTo(w_left_right);
  180. make.right.mas_equalTo(-w_left_right);
  181. make.height.mas_equalTo(inputTextFieldBGH);
  182. }];
  183. }
  184. - (void)smsCodeBtnPressed:(id)sender{
  185. if ([delegate respondsToSelector:@selector(smsCodeBtnBePressed:smsCodeInputView:)]){
  186. [delegate smsCodeBtnBePressed:sender smsCodeInputView:phoneNumInput];
  187. }
  188. }
  189. - (void)hiddenKeyboard{
  190. [self.phoneNumInput resignFirstResponder];
  191. [self.smsInput resignFirstResponder];
  192. }
  193. @end