// // FKProductRecommendCell.m // FirstLink // // Created by jack on 16/1/14. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProductRecommendCell.h" #import "FKProDetailViewModel.h" @interface FKProductRecommendCell () @property (nonatomic, strong) UIImageView *headerImgView; @property (nonatomic, strong) UILabel *nameLabel; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UIView *bottomLine; @end @implementation FKProductRecommendCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self addAllSubviews]; self.contentView.backgroundColor = [UIColor whiteColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.headerImgView]; [self.contentView addSubview:self.nameLabel]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.bottomLine]; [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(10); make.left.equalTo(self.contentView).offset(15); make.size.mas_equalTo(CGSizeMake(50, 50)); }]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerImgView.mas_right).offset(11); make.centerY.equalTo(self.headerImgView); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.headerImgView.mas_bottom).offset(13); make.left.equalTo(self.contentView).offset(15); make.right.equalTo(self.contentView).offset(- 15); }]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self.contentView); make.height.mas_equalTo(0.5); }]; } + (CGFloat)cellHeightForTitleText:(NSString *)text{ CGFloat textHeight = [FLStringHelper sizeOfAttributeString:text lineSpace:2.4 width:UISCREENWIDTH - 30 font:([UIFont systemFontOfSize:14]) maxRow:NSIntegerMax].height; return textHeight + 28 + 50 + 10; } //- (void)fk_configWithViewModel:(FKProductDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{ // if ([viewModel isKindOfClass:[FKProductDetailViewModel class]]) { // // self.nameLabel.text = [NSString stringWithFormat:@"%@ 推荐", viewModel.dataItem.recommendInfo.nickName]; // self.titleLabel.attributedText = [FLStringHelper attStringWithText:viewModel.dataItem.recommendInfo.recommendTitle lineSpace:2.4]; // [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:viewModel.dataItem.recommendInfo.headerPicUrl]]; // } //} - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) { FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; self.nameLabel.text = [NSString stringWithFormat:@"%@ 推荐", detailModel.dataItem.recommendInfo.nickName]; self.titleLabel.attributedText = [FLStringHelper attStringWithText:detailModel.dataItem.recommendInfo.recommendTitle lineSpace:2.4]; [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:detailModel.dataItem.recommendInfo.headerPicUrl]]; } } #pragma mark - property - (UIImageView *)headerImgView{ if (_headerImgView == nil) { _headerImgView = [[UIImageView alloc]init]; _headerImgView.layer.cornerRadius = 25; _headerImgView.layer.masksToBounds = YES; } return _headerImgView; } - (UILabel *)nameLabel{ if (_nameLabel == nil) { _nameLabel = [[UILabel alloc]init]; _nameLabel.textColor = UIColorFromRGB(0x9B9B9B); _nameLabel.font = [UIFont systemFontOfSize:13]; } return _nameLabel; } - (UILabel *)titleLabel{ if (_titleLabel == nil) { _titleLabel = [[UILabel alloc]init]; _titleLabel.textColor = UIColorFromRGB(0x666666); _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.numberOfLines = 0; _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; } return _titleLabel; } - (UIView *)bottomLine{ if (_bottomLine == nil) { _bottomLine = [[UIView alloc]init]; _bottomLine.backgroundColor = UIColorFromRGB(0xe5e5e5); } return _bottomLine; } @end