// // FKProTitleCell.m // FirstLink // // Created by jack on 16/8/12. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProTitleCell.h" #import "FKProDetailViewModel.h" @interface FKProTitleCell () @property (nonatomic, strong) UIView *topLine; @property (nonatomic, strong) UIView *vertLine; @property (nonatomic, strong) UIButton *priceWarnBtn; @end @implementation FKProTitleCell - (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.titleLabel]; [self.contentView addSubview:self.priceWarnBtn]; [self.contentView addSubview:self.priceWarnActBtn]; [self.contentView addSubview:self.vertLine]; [self.contentView addSubview:self.topLine]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(15); make.right.equalTo(self.vertLine.mas_left).offset(- 15); make.bottom.top.equalTo(self.contentView); }]; [self.priceWarnBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView.mas_right).offset(- 30); make.top.equalTo(self.contentView).offset(12); make.width.height.mas_equalTo(35); }]; [self.vertLine mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.priceWarnBtn.mas_left).offset(- 12.5); make.size.mas_equalTo(CGSizeMake(0.5, 30)); make.centerY.equalTo(self.priceWarnBtn); }]; [self.priceWarnActBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.vertLine); make.top.right.bottom.equalTo(self.contentView); }]; [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.contentView); make.height.mas_equalTo(0.5); }]; } + (CGFloat)cellHeightForTitle:(NSString *)title{ CGFloat textH = [FLStringHelper sizeOfAttributeString:title lineSpace:2.4 width:UISCREENWIDTH - 85 font:[UIFont systemFontOfSize:15] maxRow:0].height; return MAX(50, textH + 17); } //+ (CGFloat)cellHeight{ // return 62.0f; //} - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) { FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel; self.titleLabel.attributedText = [FLStringHelper attStringWithText:detailModel.dataItem.productInfo.name lineSpace:2.4f]; } } #pragma mark - property - (UILabel *)titleLabel{ if (_titleLabel == nil) { _titleLabel = [[UILabel alloc]init]; _titleLabel.textColor = UIColorFromRGB(0x4a4a4a); _titleLabel.font = [UIFont systemFontOfSize:15]; _titleLabel.numberOfLines = 0; _titleLabel.textAlignment = NSTextAlignmentCenter; } return _titleLabel; } - (UIButton *)priceWarnBtn{ if (_priceWarnBtn == nil) { _priceWarnBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_priceWarnBtn setTitle:@"降价\n通知" forState:UIControlStateNormal]; [_priceWarnBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal]; _priceWarnBtn.titleLabel.font = [UIFont systemFontOfSize:10]; _priceWarnBtn.titleLabel.numberOfLines = 0; _priceWarnBtn.layer.cornerRadius = 17.5f; _priceWarnBtn.layer.borderColor = UIColorFromRGB(0x999999).CGColor; _priceWarnBtn.layer.borderWidth = 0.5; _priceWarnBtn.layer.masksToBounds = YES; _priceWarnBtn.userInteractionEnabled = NO; } return _priceWarnBtn; } - (UIButton *)priceWarnActBtn{ if (_priceWarnActBtn == nil) { _priceWarnActBtn = [UIButton buttonWithType:UIButtonTypeCustom]; } return _priceWarnActBtn; } - (UIView *)vertLine{ if (_vertLine == nil) { _vertLine = [[UIView alloc]init]; _vertLine.backgroundColor = UIColorFromRGB(0xcccccc); } return _vertLine; } - (UIView *)topLine{ if (_topLine == nil) { _topLine = [[UIView alloc]init]; _topLine.backgroundColor = UIColorFromRGB(0xe5e5e5); } return _topLine; } @end