JXCategoryTitleBackgroundCell.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // JXCategoryTitleBackgroundCell.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2019/8/16.
  6. // Copyright © 2019 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryTitleBackgroundCell.h"
  9. #import "JXCategoryTitleBackgroundCellModel.h"
  10. @interface JXCategoryTitleBackgroundCell()
  11. @property (nonatomic, strong) CALayer *bgLayer;
  12. @end
  13. @implementation JXCategoryTitleBackgroundCell
  14. - (void)initializeViews {
  15. [super initializeViews];
  16. self.bgLayer = [CALayer layer];
  17. [self.contentView.layer insertSublayer:self.bgLayer atIndex:0];
  18. }
  19. - (void)layoutSubviews {
  20. [super layoutSubviews];
  21. JXCategoryTitleBackgroundCellModel *myCellModel = (JXCategoryTitleBackgroundCellModel *)self.cellModel;
  22. [CATransaction begin];
  23. [CATransaction setDisableActions:YES];
  24. CGFloat bgWidth = self.contentView.bounds.size.width;
  25. if (myCellModel.backgroundWidth != JXCategoryViewAutomaticDimension) {
  26. bgWidth = myCellModel.backgroundWidth;
  27. }
  28. CGFloat bgHeight = self.contentView.bounds.size.height;
  29. if (myCellModel.backgroundHeight != JXCategoryViewAutomaticDimension) {
  30. bgHeight = myCellModel.backgroundHeight;
  31. }
  32. self.bgLayer.bounds = CGRectMake(0, 0, bgWidth, bgHeight);
  33. self.bgLayer.position = self.contentView.center;
  34. [CATransaction commit];
  35. }
  36. - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
  37. [super reloadData:cellModel];
  38. JXCategoryTitleBackgroundCellModel *myCellModel = (JXCategoryTitleBackgroundCellModel *)cellModel;
  39. [CATransaction begin];
  40. [CATransaction setDisableActions:YES];
  41. self.bgLayer.borderWidth = myCellModel.borderLineWidth;
  42. self.bgLayer.cornerRadius = myCellModel.backgroundCornerRadius;
  43. if (myCellModel.isSelected) {
  44. self.bgLayer.backgroundColor = myCellModel.selectedBackgroundColor.CGColor;
  45. self.bgLayer.borderColor = myCellModel.selectedBorderColor.CGColor;
  46. }else {
  47. self.bgLayer.backgroundColor = myCellModel.normalBackgroundColor.CGColor;
  48. self.bgLayer.borderColor = myCellModel.normalBorderColor.CGColor;
  49. }
  50. [CATransaction commit];
  51. }
  52. @end