YMAdolescentModelPasswordView.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // YMAdolescentModelPasswordView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/23.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAdolescentModelPasswordView.h"
  9. #import "YMAdolescentModelViewModel.h"
  10. @interface YMAdolescentModelPasswordView ()
  11. /// 青少年模式VM
  12. @property (nonatomic, strong) YMAdolescentModelViewModel *viewModel;
  13. /// 青少年模式密码操作标签
  14. @property (nonatomic, strong) UILabel *adolescentModelPasswordOperationLb;
  15. /// 密码文本框
  16. @property (nonatomic, strong) YMCaptchaTextView *passwordTextView;
  17. @end
  18. @implementation YMAdolescentModelPasswordView
  19. - (void)ym_setupViews{
  20. [self addSubview:self.adolescentModelPasswordOperationLb];
  21. [self addSubview:self.passwordTextView];
  22. [self setNeedsUpdateConstraints];
  23. [self updateConstraintsIfNeeded];
  24. }
  25. - (void)updateConstraints{
  26. [self.adolescentModelPasswordOperationLb mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.top.equalTo(self).offset(adapt(30));
  28. make.left.equalTo(self).offset(adapt(15));
  29. make.right.equalTo(self).offset(adapt(-15));
  30. }];
  31. [self.passwordTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.top.equalTo(self.adolescentModelPasswordOperationLb.mas_bottom).offset(adapt(20));
  33. make.left.equalTo(self).offset(adapt(15));
  34. make.right.equalTo(self).offset(adapt(-15));
  35. make.bottom.equalTo(self).offset(adapt(-30)).priorityHigh();
  36. make.height.mas_equalTo(adapt(60));
  37. }];
  38. [super updateConstraints];
  39. }
  40. - (void)ym_bindViewModel:(YMAdolescentModelViewModel *)viewModel{
  41. if (!viewModel) {
  42. return;
  43. }
  44. _viewModel = viewModel;
  45. RAC(self.adolescentModelPasswordOperationLb, text) = RACObserve(self.viewModel, adolescentModelPasswordOperationText);
  46. }
  47. - (UILabel *)adolescentModelPasswordOperationLb{
  48. if (!_adolescentModelPasswordOperationLb) {
  49. _adolescentModelPasswordOperationLb = [[UILabel alloc]init];
  50. _adolescentModelPasswordOperationLb.font = LCBoldFont(25);
  51. _adolescentModelPasswordOperationLb.textColor = HexColorFromRGB(0x333333);
  52. _adolescentModelPasswordOperationLb.textAlignment = NSTextAlignmentLeft;
  53. _adolescentModelPasswordOperationLb.text = @"密码操作";
  54. }
  55. return _adolescentModelPasswordOperationLb;
  56. }
  57. - (YMCaptchaTextView *)passwordTextView{
  58. if (!_passwordTextView) {
  59. YMCaptchaTextCellProperty *cellProperty = [[YMCaptchaTextCellProperty alloc]init];
  60. cellProperty.cellBgColorNormal = HexColorFromRGB(0xF6F6F6);
  61. cellProperty.cellBgColorSelected = HexColorFromRGB(0xF6F6F6);
  62. cellProperty.cellBgColorFilled = HexColorFromRGB(0xF6F6F6);
  63. cellProperty.cellCursorColor = HexColorFromRGB(0xfd7bc5);
  64. cellProperty.cellCursorWidth = 2;
  65. cellProperty.cellCursorHeight = adapt(18);
  66. cellProperty.cornerRadius = adapt(10);
  67. cellProperty.borderWidth = 0;
  68. cellProperty.cellFont = LCBoldFont(25);
  69. cellProperty.cellTextColor = HexColorFromRGB(0x000000);
  70. cellProperty.showLine = NO;
  71. cellProperty.customLineViewBlock = ^YMCaptchaTextLineView * _Nonnull{
  72. YMCaptchaTextLineView *lineView = [[YMCaptchaTextLineView alloc]init];
  73. lineView.underlineColorNormal = HexColorFromRGBA(0xCBCBCB, 0.72);
  74. lineView.underlineColorSelected = HexColorFromRGBA(0xCBCBCB, 0.72);
  75. lineView.underlineColorFilled = HexColorFromRGBA(0xCBCBCB, 0.72);
  76. [lineView.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
  77. make.height.mas_equalTo(adapt(1.5));
  78. make.left.right.bottom.offset(0);
  79. }];
  80. lineView.selectChangeBlock = ^(YMCaptchaTextLineView * _Nonnull lineView, BOOL selected) {
  81. if (selected) {
  82. [lineView.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
  83. make.height.mas_equalTo(adapt(1.5));
  84. }];
  85. } else {
  86. [lineView.lineView mas_updateConstraints:^(MASConstraintMaker *make) {
  87. make.height.mas_equalTo(adapt(1.5));
  88. }];
  89. }
  90. };
  91. return lineView;
  92. };
  93. _passwordTextView = [[YMCaptchaTextView alloc] initWithCodeLength:4];
  94. _passwordTextView.captchaTextFlowLayout.itemSize = CGSizeMake(adapt(70), adapt(45));
  95. _passwordTextView.customCellProperty = cellProperty;
  96. @weakify(self)
  97. _passwordTextView.textDidChangeblock = ^(NSString *text, BOOL isFinished) {
  98. @strongify(self)
  99. switch (self.viewModel.adolescentModelType) {
  100. case YMAdolescentModelTypeTips:
  101. break;
  102. case YMAdolescentModelTypeSettingPassword:
  103. {
  104. self.viewModel.adolescentModelSettingPassword = text;
  105. }
  106. break;
  107. case YMAdolescentModelTypeConfirmPassword:
  108. {
  109. self.viewModel.adolescentModelConfirmPassword = text;
  110. }
  111. break;
  112. case YMAdolescentModelTypeClosePassword:
  113. {
  114. self.viewModel.adolescentModelConfirmPassword = text;
  115. }
  116. break;
  117. default:
  118. break;
  119. }
  120. };
  121. [_passwordTextView loadAndPrepareViewWithBeginEdit:NO];
  122. }
  123. return _passwordTextView;
  124. }
  125. @end