// // YOUPAIJXCategoryTitleBackgroundCell.m // JXCategoryView // // Created by jiaxin on 2019/8/16. // Copyright © 2019 jiaxin. All rights reserved. // #import "YOUPAIJXCategoryTitleBackgroundCell.h" #import "YOUPAIJXCategoryTitleBackgroundCellModel.h" @interface YOUPAIJXCategoryTitleBackgroundCell() @property (nonatomic, strong) CALayer *youpaipbgLayer; @end @implementation YOUPAIJXCategoryTitleBackgroundCell - (void)initializeViews { [super initializeViews]; self.youpaipbgLayer = [CALayer layer]; [self.contentView.layer insertSublayer:self.youpaipbgLayer atIndex:0]; } - (void)layoutSubviews { [super layoutSubviews]; YOUPAIJXCategoryTitleBackgroundCellModel *myCellModel = (YOUPAIJXCategoryTitleBackgroundCellModel *)self.cellModel; [CATransaction begin]; [CATransaction setDisableActions:YES]; CGFloat bgWidth = self.contentView.bounds.size.width; if (myCellModel.backgroundWidth != JXCategoryViewAutomaticDimension) { bgWidth = myCellModel.backgroundWidth; } CGFloat bgHeight = self.contentView.bounds.size.height; if (myCellModel.backgroundHeight != JXCategoryViewAutomaticDimension) { bgHeight = myCellModel.backgroundHeight; } self.youpaipbgLayer.bounds = CGRectMake(0, 0, bgWidth, bgHeight); self.youpaipbgLayer.position = self.contentView.center; [CATransaction commit]; } - (void)reloadData:(JXCategoryBaseCellModel *)cellModel { [super reloadData:cellModel]; YOUPAIJXCategoryTitleBackgroundCellModel *myCellModel = (YOUPAIJXCategoryTitleBackgroundCellModel *)cellModel; [CATransaction begin]; [CATransaction setDisableActions:YES]; self.youpaipbgLayer.borderWidth = myCellModel.borderLineWidth; self.youpaipbgLayer.cornerRadius = myCellModel.backgroundCornerRadius; if (myCellModel.isSelected) { self.youpaipbgLayer.backgroundColor = myCellModel.selectedBackgroundColor.CGColor; self.youpaipbgLayer.borderColor = myCellModel.selectedBorderColor.CGColor; }else { self.youpaipbgLayer.backgroundColor = myCellModel.normalBackgroundColor.CGColor; self.youpaipbgLayer.borderColor = myCellModel.normalBorderColor.CGColor; } [CATransaction commit]; } @end