JXCategoryNumberCell.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. @end
  12. @implementation JXCategoryNumberCell
  13. - (void)initializeViews {
  14. [super initializeViews];
  15. self.numberLabel = ({
  16. UILabel *label = [[UILabel alloc] init];
  17. label.textAlignment = NSTextAlignmentCenter;
  18. label.layer.masksToBounds = YES;
  19. label;
  20. });
  21. [self.contentView addSubview:self.numberLabel];
  22. }
  23. - (void)layoutSubviews {
  24. [super layoutSubviews];
  25. [self.numberLabel sizeToFit];
  26. JXCategoryNumberCellModel *myCellModel = (JXCategoryNumberCellModel *)self.cellModel;
  27. self.numberLabel.bounds = CGRectMake(0, 0, self.numberLabel.bounds.size.width + myCellModel.numberLabelWidthIncrement, myCellModel.numberLabelHeight);
  28. self.numberLabel.layer.cornerRadius = myCellModel.numberLabelHeight/2.0;
  29. self.numberLabel.center = CGPointMake(CGRectGetMaxX(self.titleLabel.frame)+myCellModel.numberLabelOffset.x, CGRectGetMinY(self.titleLabel.frame)+myCellModel.numberLabelOffset.y);
  30. }
  31. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  32. [super reloadData:cellModel];
  33. JXCategoryNumberCellModel *myCellModel = (JXCategoryNumberCellModel *)cellModel;
  34. self.numberLabel.hidden = myCellModel.count == 0;
  35. self.numberLabel.backgroundColor = myCellModel.numberBackgroundColor;
  36. self.numberLabel.font = myCellModel.numberLabelFont;
  37. self.numberLabel.textColor = myCellModel.numberTitleColor;
  38. self.numberLabel.text = myCellModel.numberString;
  39. [self setNeedsLayout];
  40. }
  41. @end