QtyCountV.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // QtyCountV.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/10/10.
  6. //
  7. #import "QtyCountV.h"
  8. @implementation QtyCountV
  9. - (void)tt_setupViews{
  10. [self addSubview:self.numLab];
  11. [self addSubview:self.cutBtn];
  12. [self addSubview:self.addBtn];
  13. [self tt_setupViewsFrame];
  14. }
  15. - (void)tt_setupViewsFrame{
  16. [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
  17. make.top.mas_equalTo(0);
  18. make.height.mas_equalTo(32);
  19. make.width.mas_equalTo(46);
  20. make.centerX.mas_equalTo(0);
  21. }];
  22. [self.cutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.top.mas_equalTo(0);
  24. make.right.equalTo(self.numLab.mas_left);
  25. make.height.mas_equalTo(32);
  26. make.width.mas_equalTo(32);
  27. }];
  28. [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.mas_equalTo(0);
  30. make.left.equalTo(self.numLab.mas_right);
  31. make.height.mas_equalTo(32);
  32. make.width.mas_equalTo(32);
  33. }];
  34. }
  35. #pragma mark - *************** handle ****************
  36. -(void)handle_addNumEvent:(UIButton *)btn{
  37. NSInteger num = [self.numLab.text integerValue] +1;
  38. [self tool_btnChangeNum:num];
  39. // self.numLab.text = [NSString stringWithFormat:@"%ld",num];
  40. if(self.ViewtapClose){
  41. self.ViewtapClose(1, [NSString stringWithFormat:@"%ld",num]);
  42. }
  43. }
  44. -(void)handle_cutNumEvent:(UIButton *)btn{
  45. NSInteger num = [self.numLab.text integerValue] -1;
  46. [self tool_btnChangeNum:num];
  47. // self.numLab.text = [NSString stringWithFormat:@"%ld", num];
  48. if(self.ViewtapClose){
  49. self.ViewtapClose(0, [NSString stringWithFormat:@"%ld",num]);
  50. }
  51. }
  52. -(void)xxx_changeBtnIsEnable:(BOOL)isEnabled num:(NSInteger)num{
  53. if(isEnabled){
  54. [self tool_btnChangeNum:num];
  55. }else{
  56. [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  57. self.addBtn.userInteractionEnabled = NO;
  58. [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  59. self.cutBtn.userInteractionEnabled = NO;
  60. }
  61. }
  62. -(void)tool_btnChangeNum:(NSInteger )num{
  63. if(num >= self.goodsmaxNum){
  64. [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  65. self.addBtn.userInteractionEnabled = NO;
  66. }else{
  67. [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  68. self.addBtn.userInteractionEnabled = YES;
  69. }
  70. if(num >= 2){
  71. [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  72. self.cutBtn.userInteractionEnabled = YES;
  73. }else{
  74. [self.cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  75. self.cutBtn.userInteractionEnabled = NO;
  76. }
  77. }
  78. -(UIButton *)cutBtn{
  79. if(!_cutBtn){
  80. _cutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  81. [_cutBtn setTitle:@"-" forState:UIControlStateNormal];
  82. [_cutBtn setTitleColor:[UIColor colorWithHexString:@"#E6E6E6"] forState:UIControlStateNormal];
  83. _cutBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
  84. _cutBtn.layer.borderWidth = 0.5;
  85. [_cutBtn addTarget:self action:@selector(handle_cutNumEvent:) forControlEvents:UIControlEventTouchUpInside];
  86. _cutBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  87. _cutBtn.userInteractionEnabled = NO;
  88. }
  89. return _cutBtn;
  90. }
  91. -(UILabel *)numLab{
  92. if(!_numLab){
  93. _numLab = [[UILabel alloc]init];
  94. _numLab.text = @"1";
  95. _numLab.font = [UIFont fontWithName:Rob_Bold size:12];
  96. _numLab.textAlignment = NSTextAlignmentCenter;
  97. _numLab.layer.borderWidth = 0.5;
  98. _numLab.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  99. }
  100. return _numLab;
  101. }
  102. -(UIButton *)addBtn{
  103. if(!_addBtn){
  104. _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  105. [_addBtn setTitle:@"+" forState:UIControlStateNormal];
  106. [_addBtn setTitleColor:[UIColor colorWithHexString:@"#0B0B0B"] forState:UIControlStateNormal];
  107. _addBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:18];
  108. _addBtn.layer.borderWidth = 0.5;
  109. _addBtn.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
  110. [_addBtn addTarget:self action:@selector(handle_addNumEvent:) forControlEvents:UIControlEventTouchUpInside];
  111. }
  112. return _addBtn;
  113. }
  114. @end