// // FKProBrandCell.m // FirstLink // // Created by jack on 16/8/13. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProBrandCell.h" #import "FKProDetailViewModel.h" @interface FKProBrandCell () @property (nonatomic, strong) UIImageView *brandImgView; @property (nonatomic, strong) UILabel *brandLabel; @property (nonatomic, strong) UILabel *countLabel; @property (nonatomic, strong) UILabel *contentLabel; //@property (nonatomic, strong) MASConstraint *widthConst; @end @implementation FKProBrandCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self addAllSubviews]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = [UIColor whiteColor]; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.brandImgView]; [self.contentView addSubview:self.bookButton]; [self.contentView addSubview:self.brandLabel]; [self.contentView addSubview:self.countLabel]; [self.contentView addSubview:self.contentLabel]; [self.contentView addSubview:self.brandButton]; [self.contentView addSubview:self.arrowBtn]; [self.brandImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(15); make.left.equalTo(self.contentView).offset(15); make.size.mas_equalTo(CGSizeMake(41, 41)); }]; [self.brandButton mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.brandImgView); make.size.mas_equalTo(CGSizeMake(50, 50)); }]; [self.bookButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(- 15); make.centerY.equalTo(self.brandImgView); make.size.mas_equalTo(CGSizeMake(55, 22)); }]; [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.brandImgView.mas_bottom).offset(10); make.left.equalTo(self.contentView).offset(15); make.right.equalTo(self.contentView).offset(-35); make.bottom.equalTo(self.contentView).offset(-10); }]; [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.contentLabel.mas_bottom).offset(- 15); make.centerX.equalTo(self.contentView.mas_right).offset(- 20); make.size.mas_equalTo(CGSizeMake(40, 40)); }]; } + (CGFloat)cellHeightForContent:(NSString *)content{ if (![FLStringHelper isValidString:content]) return 66; CGFloat contentH = [FLStringHelper sizeOfAttributeString:content lineSpace:2.4 width:UISCREENWIDTH - 50 font:[UIFont systemFontOfSize:13] maxRow:NSIntegerMax].height; return contentH + 77; } - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) { FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; [self.brandImgView setImageWithURL:detailModel.brandRecItem.brandInfo.picUrl cdnWidth:41]; NSString *countTip = [FKProBrandCell validProductCountTip:detailModel.brandRecItem.brandInfo.validProdCount]; if (countTip) { [self.brandLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.brandImgView.mas_right).offset(7); make.centerY.equalTo(self.brandImgView).offset(-8); }]; [self.countLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.brandImgView.mas_right).offset(7); make.centerY.equalTo(self.brandImgView).offset(8); }]; } else { [self.brandLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.brandImgView.mas_right).offset(7); make.centerY.equalTo(self.brandImgView); }]; } self.brandLabel.text = detailModel.brandRecItem.brandInfo.brandName; self.countLabel.text = countTip; self.bookButton.selected = detailModel.brandRecItem.brandInfo.hasBook; NSAttributedString *attM = [FLStringHelper attStringWithText:detailModel.brandRecItem.brandInfo.desc lineSpace:2.4]; self.contentLabel.attributedText = attM; NSString *arrowImgName = detailModel.isBrandDescClose ? @"brandDownArrow" : @"brandUpArrow"; [_arrowBtn setImage:[UIImage imageNamed:arrowImgName] forState:UIControlStateNormal]; } } #pragma mark - Private Method + (NSString *)validProductCountTip:(NSString *)countString { if (countString.integerValue >= 10) { NSString *text = countString; if (countString.integerValue >= 10000) { text = [NSString stringWithFormat:@"%ldw+", countString.integerValue/10000]; } return [NSString stringWithFormat:@"%@件畅销商品", text];; } return nil; } #pragma mark - property - (UIImageView *)brandImgView{ if (_brandImgView == nil) { _brandImgView = [[UIImageView alloc]init]; _brandImgView.layer.borderWidth = 0.5; _brandImgView.layer.borderColor = UIColorFromRGB(0xe5e5e5).CGColor; _brandImgView.contentMode = UIViewContentModeScaleAspectFit; } return _brandImgView; } - (UILabel *)brandLabel{ if (_brandLabel == nil) { _brandLabel = [[UILabel alloc]init]; _brandLabel.textColor = UIColorFromRGB(0x333333); _brandLabel.font = [UIFont systemFontOfSize:13]; } return _brandLabel; } - (UILabel *)countLabel { if (_countLabel == nil) { _countLabel = [[UILabel alloc]init]; _countLabel.textAlignment = NSTextAlignmentLeft; _countLabel.textColor = UIColorFromRGB(0x999999); _countLabel.font = [UIFont systemFontOfSize:12]; } return _countLabel; } - (UIButton *)brandButton{ if (_brandButton == nil) { _brandButton = [UIButton buttonWithType:UIButtonTypeCustom]; } return _brandButton; } - (UIButton *)bookButton{ if (_bookButton == nil) { _bookButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_bookButton setTitle:@"+ 订阅" forState:UIControlStateNormal]; [_bookButton setTitle:@"取消订阅" forState:UIControlStateSelected]; [_bookButton setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal]; [_bookButton setTitleColor:UIColorFromRGB(0xcccccc) forState:UIControlStateSelected]; _bookButton.layer.cornerRadius = 11.0f; _bookButton.layer.borderWidth = 0.5; _bookButton.layer.borderColor = UIColorFromRGB(0xcccccc).CGColor; _bookButton.layer.masksToBounds = YES; _bookButton.titleLabel.font = [UIFont systemFontOfSize:10]; _bookButton.selected = NO; } return _bookButton; } - (UILabel *)contentLabel{ if (_contentLabel == nil) { _contentLabel = [[UILabel alloc]init]; _contentLabel.textColor = UIColorFromRGB(0x666666); _contentLabel.font = [UIFont systemFontOfSize:13]; _contentLabel.numberOfLines = 0; } return _contentLabel; } - (UIButton *)arrowBtn { if (!_arrowBtn) { _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _arrowBtn; } @end