YMImproveInfoGenderView.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // YMImproveInfoGenderView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/9.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMImproveInfoGenderView.h"
  9. #import "YMImproveInfoViewModel.h"
  10. @interface YMImproveInfoGenderView ()<YMChoiceButtonDelegate>
  11. /// 完善信息VM
  12. @property (nonatomic, strong) YMImproveInfoViewModel *viewModel;
  13. /// 男性单选按钮
  14. @property (nonatomic, strong) YMChoiceButton *maleChoiceBtn;
  15. /// 女性单选按钮
  16. @property (nonatomic, strong) YMChoiceButton *femaleChoiceBtn;
  17. @property (nonatomic, strong) UILabel *genderTitleLb;
  18. @end
  19. @implementation YMImproveInfoGenderView
  20. - (void)ym_setupViews{
  21. [self addSubview:self.genderTitleLb];
  22. [self addSubview:self.maleChoiceBtn];
  23. [self addSubview:self.femaleChoiceBtn];
  24. [self setNeedsUpdateConstraints];
  25. [self updateConstraintsIfNeeded];
  26. }
  27. - (void)updateConstraints{
  28. [self.genderTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.equalTo(self);
  30. make.left.equalTo(self);
  31. make.height.mas_equalTo(adapt(22));
  32. }];
  33. [self.maleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self.genderTitleLb.mas_bottom).offset(adapt(5));
  35. make.left.equalTo(self);
  36. make.width.mas_equalTo(adapt(100));
  37. make.height.mas_equalTo(adapt(48));
  38. }];
  39. [self.femaleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self.genderTitleLb.mas_bottom).offset(adapt(5));
  41. make.left.equalTo(self.maleChoiceBtn.mas_right).offset(adapt(10));
  42. make.width.mas_equalTo(adapt(100));
  43. make.height.mas_equalTo(adapt(48));
  44. }];
  45. [super updateConstraints];
  46. }
  47. - (void)ym_bindViewModel:(YMImproveInfoViewModel *)viewModel{
  48. if (!viewModel) {
  49. return;
  50. }
  51. _viewModel = viewModel;
  52. self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  53. self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  54. self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0x8DA0FE).CGColor;
  55. self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
  56. }
  57. - (void)ym_choiceButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
  58. switch (index) {
  59. case 2:
  60. {
  61. self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  62. self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  63. self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0x8DA0FE).CGColor;
  64. self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
  65. }
  66. break;
  67. case 1:
  68. {
  69. self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  70. self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  71. self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
  72. self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xFA8FAA).CGColor;
  73. }
  74. break;
  75. default:
  76. break;
  77. }
  78. self.viewModel.genderType = index;
  79. dispatch_async(dispatch_get_main_queue(), ^{
  80. [[YMGlobalUtils getCurrentVC].view endEditing:YES];
  81. });
  82. }
  83. - (void)ym_choiceButtonCancelAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
  84. }
  85. - (UILabel *)genderTitleLb{
  86. if (!_genderTitleLb) {
  87. _genderTitleLb = [[UILabel alloc]init];
  88. _genderTitleLb.font = LCFont(13);
  89. _genderTitleLb.textColor = HexColorFromRGBA(0x333333,1);
  90. _genderTitleLb.textAlignment = NSTextAlignmentLeft;
  91. _genderTitleLb.text = @"性别";
  92. }
  93. return _genderTitleLb;
  94. }
  95. - (YMChoiceButton *)maleChoiceBtn{
  96. if (!_maleChoiceBtn) {
  97. _maleChoiceBtn = [YMChoiceButton buttonWithFrame:CGRectZero andChoiceType:YMChoiceTypeRadio withIndex:2 inGroup:@"gender" withSelectedImage:ImageByName(@"ym_improve_info_male_selected_icon") andNormalImage:ImageByName(@"ym_improve_info_male_normal_icon")];
  98. [_maleChoiceBtn setTitle:@" 男生" forState:UIControlStateNormal];
  99. _maleChoiceBtn.titleLabel.font = LCBoldFont(13);
  100. [_maleChoiceBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  101. //_maleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  102. //[_maleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
  103. //CGFloat margin = 3;
  104. //_maleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
  105. _maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  106. _maleChoiceBtn.selected = YES;
  107. _maleChoiceBtn.mustChooseOne = YES;
  108. _maleChoiceBtn.layer.cornerRadius = adapt(24);
  109. _maleChoiceBtn.layer.masksToBounds = true;
  110. _maleChoiceBtn.layer.borderWidth = 1;
  111. _maleChoiceBtn.delegate = self;
  112. }
  113. return _maleChoiceBtn;
  114. }
  115. - (YMChoiceButton *)femaleChoiceBtn{
  116. if (!_femaleChoiceBtn) {
  117. _femaleChoiceBtn = [YMChoiceButton buttonWithFrame:CGRectZero andChoiceType:YMChoiceTypeRadio withIndex:1 inGroup:@"gender" withSelectedImage:ImageByName(@"ym_improve_info_female_selected_icon") andNormalImage:ImageByName(@"ym_improve_info_female_normal_icon")];
  118. [_femaleChoiceBtn setTitle:@" 女生" forState:UIControlStateNormal];
  119. _femaleChoiceBtn.titleLabel.font = LCBoldFont(13);
  120. [_femaleChoiceBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
  121. //_femaleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  122. //[_femaleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
  123. //CGFloat margin = 3;
  124. //_femaleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
  125. _femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
  126. _femaleChoiceBtn.mustChooseOne = YES;
  127. _femaleChoiceBtn.delegate = self;
  128. _femaleChoiceBtn.layer.cornerRadius = adapt(24);
  129. _femaleChoiceBtn.layer.masksToBounds = true;
  130. _femaleChoiceBtn.layer.borderWidth = 1;
  131. _femaleChoiceBtn.delegate = self;
  132. }
  133. return _femaleChoiceBtn;
  134. }
  135. @end