YMImproveInfoGenderView.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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(25));
  32. }];
  33. [self.maleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self.genderTitleLb.mas_bottom);
  35. make.left.equalTo(self);
  36. make.width.mas_equalTo(adapt(148));
  37. make.height.mas_equalTo(adapt(50));
  38. }];
  39. [self.femaleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self.genderTitleLb.mas_bottom);
  41. make.right.equalTo(self);
  42. make.width.mas_equalTo(adapt(148));
  43. make.height.mas_equalTo(adapt(50));
  44. }];
  45. [super updateConstraints];
  46. }
  47. - (void)ym_bindViewModel:(YMImproveInfoViewModel *)viewModel{
  48. if (!viewModel) {
  49. return;
  50. }
  51. _viewModel = viewModel;
  52. self.maleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0x000000);
  53. self.femaleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0xF8F8F8);
  54. }
  55. - (void)ym_choiceButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
  56. switch (index) {
  57. case 2:
  58. {
  59. self.maleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0x000000);
  60. self.femaleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0xF8F8F8);
  61. }
  62. break;
  63. case 1:
  64. {
  65. self.femaleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0x000000);
  66. self.maleChoiceBtn.backgroundColor = UIColor.clearColor;//HexColorFromRGB(0xF8F8F8);
  67. }
  68. break;
  69. default:
  70. break;
  71. }
  72. self.viewModel.genderType = index;
  73. dispatch_async(dispatch_get_main_queue(), ^{
  74. [[YMGlobalUtils getCurrentVC].view endEditing:YES];
  75. });
  76. }
  77. - (void)ym_choiceButtonCancelAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
  78. }
  79. - (UILabel *)genderTitleLb{
  80. if (!_genderTitleLb) {
  81. _genderTitleLb = [[UILabel alloc]init];
  82. _genderTitleLb.font = LCFont(15);
  83. _genderTitleLb.textColor = HexColorFromRGBA(0x000000,0.3);
  84. _genderTitleLb.textAlignment = NSTextAlignmentLeft;
  85. _genderTitleLb.textAlignment = NSTextAlignmentLeft;
  86. _genderTitleLb.text = @"性别(注册后不可修改)";
  87. }
  88. return _genderTitleLb;
  89. }
  90. - (YMChoiceButton *)maleChoiceBtn{
  91. if (!_maleChoiceBtn) {
  92. _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")];
  93. //[_maleChoiceBtn setTitle:@"男生" forState:UIControlStateNormal];
  94. //_maleChoiceBtn.titleLabel.font = LCBoldFont(17);
  95. //[_maleChoiceBtn setTitleColor:HexColorFromRGB(0x77F99A) forState:UIControlStateNormal];
  96. //_maleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  97. //[_maleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
  98. //CGFloat margin = 3;
  99. //_maleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
  100. _maleChoiceBtn.selected = YES;
  101. _maleChoiceBtn.mustChooseOne = YES;
  102. _maleChoiceBtn.layer.cornerRadius = adapt(11);
  103. _maleChoiceBtn.layer.masksToBounds = true;
  104. _maleChoiceBtn.delegate = self;
  105. }
  106. return _maleChoiceBtn;
  107. }
  108. - (YMChoiceButton *)femaleChoiceBtn{
  109. if (!_femaleChoiceBtn) {
  110. _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")];
  111. //[_femaleChoiceBtn setTitle:@"女生" forState:UIControlStateNormal];
  112. //_femaleChoiceBtn.titleLabel.font = LCBoldFont(17);
  113. //[_femaleChoiceBtn setTitleColor:HexColorFromRGB(0xF7798B) forState:UIControlStateNormal];
  114. //_femaleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  115. //[_femaleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
  116. //CGFloat margin = 3;
  117. //_femaleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
  118. _femaleChoiceBtn.mustChooseOne = YES;
  119. _femaleChoiceBtn.delegate = self;
  120. _femaleChoiceBtn.layer.cornerRadius = adapt(11);
  121. _femaleChoiceBtn.layer.masksToBounds = true;
  122. }
  123. return _femaleChoiceBtn;
  124. }
  125. @end