// // FKPersonOrderProductCell.m // FirstLink // // Created by ascii on 16/2/23. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKPersonOrderProductCell.h" #import "FKPersonOrderViewModel.h" #import "FKOrderGoodItem.h" @interface FKPersonOrderProductCell () @property (nonatomic, strong) UIView *productBgView; @property (nonatomic, strong) TTTAttributedLabel *titleLabel; @end @implementation FKPersonOrderProductCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor whiteColor]; [self addAllSubviews]; } return self; } #pragma mark - Layout - (void)addAllSubviews { [self.contentView addSubview:self.productBgView]; [self.productBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(-2); }]; [self.productBgView addSubview:self.productImgView]; [self.productImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.productBgView).offset(15); make.centerY.equalTo(self.productBgView); make.size.mas_equalTo(CGSizeMake(75, 75)); }]; [self.productBgView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.productImgView.mas_right).offset(12); make.right.equalTo(self.productBgView).offset(-36); make.top.equalTo(self.productImgView).offset(20); make.height.mas_equalTo(40); }]; } #pragma mark - FKPersonOrderCellDelegate - (void)configPersonOrderCell:(NSIndexPath *)indexPath classify:(FKPersonOrderClassify)classify viewModel:(FKPersonOrderViewModel *)viewModel { FKOrderGoodItem *goodItem = [viewModel goodItemAtIndex:indexPath classify:classify]; [self.productImgView setImageWithURL:goodItem.photoURL cdnWidth:75]; self.titleLabel.text = goodItem.title; self.tag = indexPath.section; } #pragma mark - Property - (UIView *)productBgView { if (!_productBgView) { _productBgView = [UIView new]; _productBgView.backgroundColor = UIColorFromRGB(0xf9f9f9); } return _productBgView; } - (UIImageView*)productImgView { if (!_productImgView) { _productImgView = [UIImageView new]; _productImgView.contentMode = UIViewContentModeScaleAspectFit; _productImgView.backgroundColor = [UIColor whiteColor]; } return _productImgView; } - (TTTAttributedLabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[TTTAttributedLabel alloc] init]; _titleLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop; _titleLabel.leading = 4.0; _titleLabel.textColor = UIColorFromRGB(0x666666); _titleLabel.font = [UIFont systemFontOfSize:14]; _titleLabel.numberOfLines = 0; } return _titleLabel; } @end