123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // YMImproveInfoGenderView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/9.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMImproveInfoGenderView.h"
- #import "YMImproveInfoViewModel.h"
- @interface YMImproveInfoGenderView ()<YMChoiceButtonDelegate>
- /// 完善信息VM
- @property (nonatomic, strong) YMImproveInfoViewModel *viewModel;
- /// 男性单选按钮
- @property (nonatomic, strong) YMChoiceButton *maleChoiceBtn;
- /// 女性单选按钮
- @property (nonatomic, strong) YMChoiceButton *femaleChoiceBtn;
- @property (nonatomic, strong) UILabel *genderTitleLb;
- @end
- @implementation YMImproveInfoGenderView
- - (void)ym_setupViews{
- [self addSubview:self.genderTitleLb];
- [self addSubview:self.maleChoiceBtn];
- [self addSubview:self.femaleChoiceBtn];
-
-
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.genderTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self);
- make.left.equalTo(self);
- make.height.mas_equalTo(adapt(22));
- }];
-
- [self.maleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.genderTitleLb.mas_bottom).offset(adapt(5));
- make.left.equalTo(self);
- make.width.mas_equalTo(adapt(100));
- make.height.mas_equalTo(adapt(48));
- }];
-
- [self.femaleChoiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.genderTitleLb.mas_bottom).offset(adapt(5));
- make.left.equalTo(self.maleChoiceBtn.mas_right).offset(adapt(10));
- make.width.mas_equalTo(adapt(100));
- make.height.mas_equalTo(adapt(48));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMImproveInfoViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
- _viewModel = viewModel;
- self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0x8DA0FE).CGColor;
- self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
-
- }
- - (void)ym_choiceButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
- switch (index) {
- case 2:
- {
- self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0x8DA0FE).CGColor;
- self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
- }
- break;
- case 1:
- {
- self.maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- self.maleChoiceBtn.layer.borderColor = HexColorFromRGB(0xF2F5FF).CGColor;
- self.femaleChoiceBtn.layer.borderColor = HexColorFromRGB(0xFA8FAA).CGColor;
- }
- break;
- default:
- break;
- }
-
- self.viewModel.genderType = index;
- dispatch_async(dispatch_get_main_queue(), ^{
- [[YMGlobalUtils getCurrentVC].view endEditing:YES];
- });
- }
- - (void)ym_choiceButtonCancelAtIndex:(NSUInteger)index inGroup:(NSString *)groupId{
-
- }
- - (UILabel *)genderTitleLb{
- if (!_genderTitleLb) {
- _genderTitleLb = [[UILabel alloc]init];
- _genderTitleLb.font = LCFont(13);
- _genderTitleLb.textColor = HexColorFromRGBA(0x333333,1);
- _genderTitleLb.textAlignment = NSTextAlignmentLeft;
- _genderTitleLb.text = @"性别";
- }
- return _genderTitleLb;
- }
- - (YMChoiceButton *)maleChoiceBtn{
- if (!_maleChoiceBtn) {
- _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")];
- [_maleChoiceBtn setTitle:@" 男生" forState:UIControlStateNormal];
- _maleChoiceBtn.titleLabel.font = LCBoldFont(13);
- [_maleChoiceBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
- //_maleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- //[_maleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- //CGFloat margin = 3;
- //_maleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- _maleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- _maleChoiceBtn.selected = YES;
- _maleChoiceBtn.mustChooseOne = YES;
- _maleChoiceBtn.layer.cornerRadius = adapt(24);
- _maleChoiceBtn.layer.masksToBounds = true;
- _maleChoiceBtn.layer.borderWidth = 1;
- _maleChoiceBtn.delegate = self;
- }
- return _maleChoiceBtn;
- }
- - (YMChoiceButton *)femaleChoiceBtn{
- if (!_femaleChoiceBtn) {
- _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")];
- [_femaleChoiceBtn setTitle:@" 女生" forState:UIControlStateNormal];
- _femaleChoiceBtn.titleLabel.font = LCBoldFont(13);
- [_femaleChoiceBtn setTitleColor:HexColorFromRGB(0x333333) forState:UIControlStateNormal];
- //_femaleChoiceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- //[_femaleChoiceBtn setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
- //CGFloat margin = 3;
- //_femaleChoiceBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -margin, 0, margin);
- _femaleChoiceBtn.backgroundColor = HexColorFromRGB(0xF2F5FF);
- _femaleChoiceBtn.mustChooseOne = YES;
- _femaleChoiceBtn.delegate = self;
- _femaleChoiceBtn.layer.cornerRadius = adapt(24);
- _femaleChoiceBtn.layer.masksToBounds = true;
- _femaleChoiceBtn.layer.borderWidth = 1;
- _femaleChoiceBtn.delegate = self;
- }
- return _femaleChoiceBtn;
- }
- @end
|