// // TFBookRackHeaderCell.m // WXReader // // Created by 谢腾飞 on 2020/12/1. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFBookRackHeaderCell.h" @interface TFBookRackHeaderCell () { UIView *bottomView; TFProductionCoverView *bookImageView; UILabel *titleLabel; YYLabel *bookDetailLabel; } @end @implementation TFBookRackHeaderCell - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = kWhiteColor; [self createSubViews]; } return self; } - (void)createSubViews { bottomView = [[UIView alloc] init]; bottomView.backgroundColor = kGrayViewColor; bottomView.layer.cornerRadius = 8; [self addSubview:bottomView]; [bottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(kHalfMargin + kQuarterMargin); make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin - kQuarterMargin); make.top.mas_equalTo(self.mas_top).with.offset(kHalfMargin); make.height.mas_equalTo(self.mas_height).with.offset(- kMargin); }]; bookImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical]; [bottomView addSubview:bookImageView]; [bookImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(bottomView.mas_left).with.offset(kHalfMargin); make.centerY.mas_equalTo(bottomView.mas_centerY); make.height.mas_equalTo(bottomView.mas_height).with.offset(- kMargin); make.width.mas_equalTo(kGeometricWidth((self.height - 2 * kMargin), 3, 4)); }]; titleLabel = [[UILabel alloc] init]; titleLabel.textColor = kBlackColor; titleLabel.textAlignment = NSTextAlignmentLeft; titleLabel.numberOfLines = 1; titleLabel.font = kMainFont; [self addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(bookImageView.mas_right).with.offset(kHalfMargin); make.top.mas_equalTo(bookImageView.mas_top).with.offset(kQuarterMargin); make.right.mas_equalTo(bottomView.mas_right).with.offset(- kHalfMargin); make.height.mas_equalTo(30); }]; bookDetailLabel = [[YYLabel alloc] init]; bookDetailLabel.textColor = kGrayTextColor; bookDetailLabel.textAlignment = NSTextAlignmentLeft; bookDetailLabel.textVerticalAlignment = YYTextVerticalAlignmentCenter; bookDetailLabel.numberOfLines = 2; bookDetailLabel.font = kFont13; [self addSubview:bookDetailLabel]; [bookDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(titleLabel.mas_left); make.top.mas_equalTo(titleLabel.mas_bottom); make.bottom.mas_equalTo(bookImageView.mas_bottom).with.offset(- kHalfMargin); make.right.mas_equalTo(titleLabel.mas_right); }]; } - (void)setProductionModel:(TFProductionModel *)productionModel { _productionModel = productionModel; if (productionModel.vertical_cover.length > 0) { bookImageView.coverImageUrl = productionModel.vertical_cover; } else if (productionModel.horizontal_cover.length > 0) { bookImageView.coverImageUrl = productionModel.horizontal_cover; } else { bookImageView.coverImageUrl = productionModel.cover; } titleLabel.text = productionModel.name?:@""; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: productionModel.production_descirption?:@""]; attributedString.lineSpacing = 3; attributedString.font = kFont13; attributedString.color = kGrayTextColor; bookDetailLabel.attributedText = attributedString; } - (void)setProductionType:(TFProductionType)productionType { _productionType = productionType; bookImageView.productionType = productionType; } @end