JXCategoryDotCell.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // JXCategoryDotCell.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2018/8/20.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryDotCell.h"
  9. #import "JXCategoryDotCellModel.h"
  10. @interface JXCategoryDotCell ()
  11. @property (nonatomic, strong) UIView *dot;
  12. @end
  13. @implementation JXCategoryDotCell
  14. - (void)initializeViews {
  15. [super initializeViews];
  16. _dot = [[UIView alloc] init];
  17. [self.contentView addSubview:self.dot];
  18. self.dot.translatesAutoresizingMaskIntoConstraints = NO;
  19. }
  20. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  21. [super reloadData:cellModel];
  22. JXCategoryDotCellModel *myCellModel = (JXCategoryDotCellModel *)cellModel;
  23. self.dot.hidden = !myCellModel.dotHidden;
  24. self.dot.backgroundColor = myCellModel.dotColor;
  25. self.dot.layer.cornerRadius = myCellModel.dotCornerRadius;
  26. [NSLayoutConstraint deactivateConstraints:self.dot.constraints];
  27. [self.dot.widthAnchor constraintEqualToConstant:myCellModel.dotSize.width].active = YES;
  28. [self.dot.heightAnchor constraintEqualToConstant:myCellModel.dotSize.height].active = YES;
  29. switch (myCellModel.relativePosition) {
  30. case JXCategoryDotRelativePosition_TopLeft:
  31. {
  32. [self.dot.centerXAnchor constraintEqualToAnchor:self.titleLabel.leadingAnchor constant:myCellModel.dotOffset.x].active = YES;
  33. [self.dot.centerYAnchor constraintEqualToAnchor:self.titleLabel.topAnchor constant:myCellModel.dotOffset.y].active = YES;
  34. }
  35. break;
  36. case JXCategoryDotRelativePosition_TopRight:
  37. {
  38. [self.dot.centerXAnchor constraintEqualToAnchor:self.titleLabel.trailingAnchor constant:myCellModel.dotOffset.x].active = YES;
  39. [self.dot.centerYAnchor constraintEqualToAnchor:self.titleLabel.topAnchor constant:myCellModel.dotOffset.y].active = YES;
  40. }
  41. break;
  42. case JXCategoryDotRelativePosition_BottomLeft:
  43. {
  44. [self.dot.centerXAnchor constraintEqualToAnchor:self.titleLabel.leadingAnchor constant:myCellModel.dotOffset.x].active = YES;
  45. [self.dot.centerYAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:myCellModel.dotOffset.y].active = YES;
  46. }
  47. break;
  48. case JXCategoryDotRelativePosition_BottomRight:
  49. {
  50. [self.dot.centerXAnchor constraintEqualToAnchor:self.titleLabel.trailingAnchor constant:myCellModel.dotOffset.x].active = YES;
  51. [self.dot.centerYAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:myCellModel.dotOffset.y].active = YES;
  52. }
  53. break;
  54. }
  55. }
  56. @end