JXVerifyPayVC.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // JXVerifyPayVC.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 2018/9/18.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXVerifyPayVC.h"
  9. #import "JXTextField.h"
  10. #define kDotSize CGSizeMake (10, 10) //密码点的大小
  11. #define kDotCount 6 //密码个数
  12. #define K_Field_Height 45 //每一个输入框的高度
  13. @interface JXVerifyPayVC () <UITextFieldDelegate>
  14. @property (nonatomic, strong) UIView *baseView;
  15. @property (nonatomic, strong) UILabel *typeLab;
  16. @property (nonatomic, strong) UILabel *RMBLab;
  17. @property (nonatomic, strong) JXTextField *textField;
  18. @property (nonatomic, strong) NSMutableArray *dotArray; //用于存放黑色的点点
  19. @property (nonatomic, strong) UIButton *disBtn;
  20. @end
  21. @implementation JXVerifyPayVC
  22. - (instancetype)init {
  23. self = [super init];
  24. if (self) {
  25. [self setupViews];
  26. [self initPwdTextField];
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
  33. self.modalPresentationStyle = UIModalPresentationCustom;
  34. [self.textField becomeFirstResponder];
  35. }
  36. - (void)setupViews {
  37. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(30, 160, JX_SCREEN_WIDTH-60, 232)];
  38. self.baseView.backgroundColor = [UIColor whiteColor];
  39. self.baseView.layer.masksToBounds = YES;
  40. self.baseView.layer.cornerRadius = 6.f;
  41. [self.view addSubview:self.baseView];
  42. self.disBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 45, 45)];
  43. [self.disBtn addTarget:self action:@selector(didDismissVerifyPayVC) forControlEvents:UIControlEventTouchUpInside];
  44. [self.baseView addSubview:self.disBtn];
  45. UIImageView *dis = [[UIImageView alloc] initWithFrame:CGRectMake(15, 35/2, 18, 18)];
  46. dis.image = [UIImage imageNamed:@"pay_cha"];
  47. [self.disBtn addSubview:dis];
  48. UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, self.baseView.frame.size.width, 22)];
  49. titleLab.text = Localized(@"JX_EnterPayPsw");
  50. titleLab.font = [UIFont boldSystemFontOfSize:19];
  51. titleLab.textAlignment = NSTextAlignmentCenter;
  52. [self.baseView addSubview:titleLab];
  53. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleLab.frame)+15, self.baseView.frame.size.width, LINE_WH)];
  54. line.backgroundColor = THE_LINE_COLOR;
  55. [self.baseView addSubview:line];
  56. self.typeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame)+15, self.baseView.frame.size.width, 20)];
  57. self.typeLab.textAlignment = NSTextAlignmentCenter;
  58. self.typeLab.font = SYSFONT(17);
  59. self.typeLab.text = [self getTypeTitle];
  60. [self.baseView addSubview:self.typeLab];
  61. if (self.type != JXVerifyTypePaymentCode) {
  62. self.RMBLab = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.typeLab.frame)+11, self.baseView.frame.size.width, 50)];
  63. self.RMBLab.textAlignment = NSTextAlignmentCenter;
  64. self.RMBLab.font = SYSFONT(46);
  65. self.RMBLab.text = [NSString stringWithFormat:@"¥%.2f",[self.RMB doubleValue]];
  66. [self.baseView addSubview:self.RMBLab];
  67. self.textField.frame = CGRectMake(16, CGRectGetMaxY(self.RMBLab.frame)+20, self.baseView.frame.size.width - 32, K_Field_Height);
  68. }else {
  69. self.textField.frame = CGRectMake(16, CGRectGetMaxY(self.typeLab.frame)+20, self.baseView.frame.size.width - 32, K_Field_Height);
  70. self.baseView.frame = CGRectMake(self.baseView.frame.origin.x, self.baseView.frame.origin.y, self.baseView.frame.size.width, CGRectGetMaxY(self.textField.frame) + 20);
  71. }
  72. [self.baseView addSubview:self.textField];
  73. }
  74. - (NSString *)getTypeTitle {
  75. NSString *string;
  76. if (self.type == JXVerifyTypeWithdrawal) {
  77. string = Localized(@"JXMoney_withdrawals");
  78. }
  79. else if (self.type == JXVerifyTypeTransfer) {
  80. string = Localized(@"JX_Transfer");
  81. }
  82. else if (self.type == JXVerifyTypeQr) {
  83. string = Localized(@"JX_Payment");
  84. }
  85. else if (self.type == JXVerifyTypeSkPay) {
  86. string = self.titleStr;
  87. }
  88. else if (self.type == JXVerifyTypePaymentCode) {
  89. string = @"开启付款码";
  90. }
  91. else {
  92. string = Localized(@"JX_ShikuRedPacket");
  93. }
  94. return string;
  95. }
  96. - (void)didDismissVerifyPayVC {
  97. if (self.delegate && [self.delegate respondsToSelector:self.didDismissVC]) {
  98. [self.delegate performSelectorOnMainThread:self.didDismissVC withObject:self waitUntilDone:NO];
  99. }
  100. }
  101. - (void)initPwdTextField
  102. {
  103. //每个密码输入框的宽度
  104. CGFloat width = (self.baseView.frame.size.width - 32) / kDotCount;
  105. //生成分割线
  106. for (int i = 0; i < kDotCount - 1; i++) {
  107. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.textField.frame) + (i + 1) * width, CGRectGetMinY(self.textField.frame), LINE_WH, K_Field_Height)];
  108. lineView.backgroundColor = [UIColor blackColor];
  109. [self.baseView addSubview:lineView];
  110. }
  111. self.dotArray = [[NSMutableArray alloc] init];
  112. //生成中间的点
  113. for (int i = 0; i < kDotCount; i++) {
  114. UIView *dotView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.textField.frame) + (width - kDotCount) / 2 + i * width, CGRectGetMinY(self.textField.frame) + (K_Field_Height - kDotSize.height) / 2, kDotSize.width, kDotSize.height)];
  115. dotView.backgroundColor = [UIColor blackColor];
  116. dotView.layer.cornerRadius = kDotSize.width / 2.0f;
  117. dotView.clipsToBounds = YES;
  118. dotView.hidden = YES; //先隐藏
  119. [self.baseView addSubview:dotView];
  120. //把创建的黑色点加入到数组中
  121. [self.dotArray addObject:dotView];
  122. }
  123. }
  124. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  125. {
  126. if([string isEqualToString:@"\n"]) {
  127. //按回车关闭键盘
  128. [textField resignFirstResponder];
  129. return NO;
  130. } else if(string.length == 0) {
  131. //判断是不是删除键
  132. return YES;
  133. }
  134. else if(textField.text.length >= kDotCount) {
  135. //输入的字符个数大于6,则无法继续输入,返回NO表示禁止输入
  136. return NO;
  137. } else {
  138. return YES;
  139. }
  140. }
  141. /**
  142. * 清除密码
  143. */
  144. - (void)clearUpPassword
  145. {
  146. self.textField.text = @"";
  147. [self textFieldDidChange:self.textField];
  148. }
  149. /**
  150. * 获取密码(MD5加密)
  151. */
  152. - (NSString *)getMD5Password {
  153. return [g_server getMD5String:self.textField.text];
  154. }
  155. /**
  156. * 重置显示的点
  157. */
  158. - (void)textFieldDidChange:(UITextField *)textField
  159. {
  160. for (UIView *dotView in self.dotArray) {
  161. dotView.hidden = YES;
  162. }
  163. for (int i = 0; i < textField.text.length; i++) {
  164. ((UIView *)[self.dotArray objectAtIndex:i]).hidden = NO;
  165. }
  166. if (textField.text.length == kDotCount) {
  167. if (self.delegate && [self.delegate respondsToSelector:self.didDismissVC]) {
  168. [self.delegate performSelectorOnMainThread:self.didVerifyPay withObject:self.textField.text waitUntilDone:NO];
  169. }
  170. }
  171. }
  172. #pragma mark - init
  173. - (UITextField *)textField
  174. {
  175. if (!_textField) {
  176. _textField = [[JXTextField alloc] init];
  177. _textField.backgroundColor = [UIColor whiteColor];
  178. //输入的文字颜色为白色
  179. _textField.textColor = [UIColor whiteColor];
  180. //输入框光标的颜色为白色
  181. _textField.tintColor = [UIColor whiteColor];
  182. _textField.delegate = self;
  183. _textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
  184. _textField.keyboardType = UIKeyboardTypeNumberPad;
  185. _textField.layer.borderColor = [[UIColor blackColor] CGColor];
  186. _textField.layer.borderWidth = LINE_WH;
  187. [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  188. }
  189. return _textField;
  190. }
  191. @end