JXCategoryNumberCell.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // JXCategoryNumberCell.m
  3. // DQGuess
  4. //
  5. // Created by jiaxin on 2018/4/9.
  6. // Copyright © 2018年 jingbo. All rights reserved.
  7. //
  8. #import "JXCategoryNumberCell.h"
  9. #import "JXCategoryNumberCellModel.h"
  10. @interface JXCategoryNumberCell ()
  11. @property (nonatomic, strong) NSLayoutConstraint *numberCenterXConstraint;
  12. @property (nonatomic, strong) NSLayoutConstraint *numberCenterYConstraint;
  13. @property (nonatomic, strong) NSLayoutConstraint *numberHeightConstraint;
  14. @property (nonatomic, strong) NSLayoutConstraint *numberWidthConstraint;
  15. @end
  16. @implementation JXCategoryNumberCell
  17. - (void)prepareForReuse {
  18. [super prepareForReuse];
  19. self.numberLabel.text = nil;
  20. }
  21. - (void)initializeViews {
  22. [super initializeViews];
  23. self.numberLabel = [[UILabel alloc] init];
  24. self.numberLabel.textAlignment = NSTextAlignmentCenter;
  25. self.numberLabel.layer.masksToBounds = YES;
  26. [self.contentView addSubview:self.numberLabel];
  27. self.numberLabel.translatesAutoresizingMaskIntoConstraints = NO;
  28. self.numberCenterXConstraint = [self.numberLabel.centerXAnchor constraintEqualToAnchor:self.titleLabel.trailingAnchor];
  29. self.numberCenterYConstraint = [self.numberLabel.centerYAnchor constraintEqualToAnchor:self.titleLabel.topAnchor];
  30. self.numberHeightConstraint = [self.numberLabel.heightAnchor constraintEqualToConstant:0];
  31. self.numberWidthConstraint = [self.numberLabel.widthAnchor constraintEqualToConstant:0];
  32. [NSLayoutConstraint activateConstraints:@[self.numberCenterXConstraint, self.numberCenterYConstraint, self.numberWidthConstraint, self.numberHeightConstraint]];
  33. }
  34. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  35. [super reloadData:cellModel];
  36. JXCategoryNumberCellModel *myCellModel = (JXCategoryNumberCellModel *)cellModel;
  37. self.numberLabel.hidden = (myCellModel.count == 0);
  38. self.numberLabel.backgroundColor = myCellModel.numberBackgroundColor;
  39. self.numberLabel.font = myCellModel.numberLabelFont;
  40. self.numberLabel.textColor = myCellModel.numberTitleColor;
  41. self.numberLabel.text = myCellModel.numberString;
  42. self.numberLabel.layer.cornerRadius = myCellModel.numberLabelHeight/2.0;
  43. self.numberHeightConstraint.constant = myCellModel.numberLabelHeight;
  44. self.numberCenterXConstraint.constant = myCellModel.numberLabelOffset.x;
  45. self.numberCenterYConstraint.constant = myCellModel.numberLabelOffset.y;
  46. if (myCellModel.count < 10 && myCellModel.shouldMakeRoundWhenSingleNumber) {
  47. self.numberWidthConstraint.constant = myCellModel.numberLabelHeight;
  48. }else {
  49. self.numberWidthConstraint.constant = myCellModel.numberStringWidth + myCellModel.numberLabelWidthIncrement;
  50. }
  51. }
  52. @end