// // QtyCountV.m // westkissMob // // Created by 王猛 on 2022/10/10. // #import "QtyCountV.h" @implementation QtyCountV - (void)tt_setupViews{ [self addSubview:self.numLab]; [self addSubview:self.cutBtn]; [self addSubview:self.addBtn]; [self tt_setupViewsFrame]; } - (void)tt_setupViewsFrame{ [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.height.mas_equalTo(32); make.width.mas_equalTo(46); make.centerX.mas_equalTo(0); }]; [self.cutBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.right.equalTo(self.numLab.mas_left); make.height.mas_equalTo(32); make.width.mas_equalTo(32); }]; [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.equalTo(self.numLab.mas_right); make.height.mas_equalTo(32); make.width.mas_equalTo(32); }]; } #pragma mark - *************** handle **************** -(void)handle_addNumEvent:(UIButton *)btn{ NSInteger num = [self.numLab.text integerValue] +1; [self tool_btnChangeNum:num]; // self.numLab.text = [NSString stringWithFormat:@"%ld",num]; if(self.ViewtapClose){ self.ViewtapClose(1, [NSString stringWithFormat:@"%ld",num]); } } -(void)handle_cutNumEvent:(UIButton *)btn{ NSInteger num = [self.numLab.text integerValue] -1; [self tool_btnChangeNum:num]; // self.numLab.text = [NSString stringWithFormat:@"%ld", num]; if(self.ViewtapClose){ self.ViewtapClose(0, [NSString stringWithFormat:@"%ld",num]); } } -(void)xxx_changeBtnIsEnable:(BOOL)isEnabled num:(NSInteger)num{ if(isEnabled){ [self tool_btnChangeNum:num]; }else{ [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal]; self.addBtn.userInteractionEnabled = NO; [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal]; self.cutBtn.userInteractionEnabled = NO; } } -(void)tool_btnChangeNum:(NSInteger )num{ if(num >= self.goodsmaxNum){ [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal]; self.addBtn.userInteractionEnabled = NO; }else{ [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal]; self.addBtn.userInteractionEnabled = YES; } if(num >= 2){ [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal]; self.cutBtn.userInteractionEnabled = YES; }else{ [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal]; self.cutBtn.userInteractionEnabled = NO; } } -(UIButton *)cutBtn{ if(!_cutBtn){ _cutBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_cutBtn setTitle:@"-" forState:UIControlStateNormal]; [_cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal]; _cutBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18]; _cutBtn.layer.borderWidth = 0.5; [_cutBtn addTarget:self action:@selector(handle_cutNumEvent:) forControlEvents:UIControlEventTouchUpInside]; _cutBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor; _cutBtn.userInteractionEnabled = NO; } return _cutBtn; } -(UILabel *)numLab{ if(!_numLab){ _numLab = [[UILabel alloc]init]; _numLab.text = @"1"; _numLab.font = [UIFont fontWithName:Rob_Bold size:12]; _numLab.textAlignment = NSTextAlignmentCenter; _numLab.layer.borderWidth = 0.5; _numLab.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor; } return _numLab; } -(UIButton *)addBtn{ if(!_addBtn){ _addBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_addBtn setTitle:@"+" forState:UIControlStateNormal]; [_addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal]; _addBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18]; _addBtn.layer.borderWidth = 0.5; _addBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor; [_addBtn addTarget:self action:@selector(handle_addNumEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _addBtn; } @end