// // FKCircleHeaderCell.m // FirstLink // // Created by jack on 16/6/12. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKCircleHeaderCell.h" #import "FKCircleBestViewModel.h" @interface FKCircleHeaderCell () @property (nonatomic, strong) UIImageView *headerImgView; @property (nonatomic, strong) UIView *vertLine; @property (nonatomic, strong) UIView *containerView; @property (nonatomic, strong) UIView *cornerCoverView; @property (nonatomic, strong) UILabel *nameLabel; @property (nonatomic, strong) UILabel *typeLabel; @property (nonatomic, strong) UILabel *timeLabel; @end @implementation FKCircleHeaderCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self addAllSubviews]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; } return self; } - (void)addAllSubviews{ [self.contentView addSubview:self.containerView]; [self.contentView addSubview:self.cornerCoverView]; [self.containerView addSubview:self.headerImgView]; [self.containerView addSubview:self.vertLine]; [self.containerView addSubview:self.nameLabel]; [self.containerView addSubview:self.typeLabel]; [self.containerView addSubview:self.timeLabel]; [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.insets(UIEdgeInsetsMake(0, 5, 0, 5)); }]; [self.cornerCoverView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self.containerView); make.height.mas_equalTo(8); }]; [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.containerView).offset(6); make.centerY.equalTo(self.containerView); make.size.mas_equalTo(CGSizeMake(40, 40)); }]; [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerImgView.mas_right).offset(10); make.bottom.equalTo(self.containerView.mas_centerY).offset(- 4); }]; [self.vertLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.headerImgView.mas_right).offset(10); make.top.equalTo(self.containerView.mas_centerY).offset(4); make.size.mas_equalTo(CGSizeMake(3, 12)); }]; [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.vertLine.mas_right).offset(5); make.centerY.equalTo(self.vertLine); }]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.containerView).offset(10); make.right.equalTo(self.containerView).offset(- 10); }]; } - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{ if ([viewModel isKindOfClass:[FKCircleBestViewModel class]]) { FKCircleBestViewModel *bestViewModel = (FKCircleBestViewModel *)viewModel; FKCircleContentItem *contentItem = [bestViewModel circleContentItemForIndexPath:indexPath]; [self.headerImgView setImageWithURL:contentItem.userItem.picUrl cdnWidth:40]; self.nameLabel.text = contentItem.userItem.nickName; if ([contentItem getCircleType] == kCircleTypeUserShare) { self.typeLabel.text = @"晒单推荐"; self.vertLine.backgroundColor = UIColorFromRGB(0xf5a623); }else if ([contentItem getCircleType] == kCircleTypeInfoShare){ self.typeLabel.text = @"种草资讯"; self.vertLine.backgroundColor = UIColorFromRGB(0xff6362); } self.timeLabel.text = contentItem.realCreateTime; } } #pragma mark - property - (UIView *)containerView{ if (_containerView == nil) { _containerView = [[UIView alloc]init]; _containerView.backgroundColor = [UIColor whiteColor]; _containerView.layer.cornerRadius = 4.0f; } return _containerView; } - (UIView *)cornerCoverView{ if (_cornerCoverView == nil) { _cornerCoverView = [[UIView alloc]init]; _cornerCoverView.backgroundColor = [UIColor whiteColor]; } return _cornerCoverView; } - (UIImageView *)headerImgView{ if (_headerImgView == nil) { _headerImgView = [[UIImageView alloc]init]; _headerImgView.layer.cornerRadius = 20; _headerImgView.layer.masksToBounds = YES; } return _headerImgView; } - (UILabel *)nameLabel{ if (_nameLabel == nil) { _nameLabel = [[UILabel alloc]init]; _nameLabel.textColor = UIColorFromRGB(0x262626); _nameLabel.font = [UIFont systemFontOfSize:14]; } return _nameLabel; } - (UILabel *)typeLabel{ if (_typeLabel == nil) { _typeLabel = [[UILabel alloc]init]; _typeLabel.textColor = UIColorFromRGB(0x262626); _typeLabel.font = [UIFont systemFontOfSize:12]; _typeLabel.numberOfLines = 1; } return _typeLabel; } - (UILabel *)timeLabel{ if (_timeLabel == nil) { _timeLabel = [[UILabel alloc]init]; _timeLabel.textColor = UIColorFromRGB(0xcccccc); _timeLabel.font = [UIFont systemFontOfSize:13]; } return _timeLabel; } - (UIView *)vertLine{ if (_vertLine == nil) { _vertLine = [[UIView alloc]init]; _vertLine.backgroundColor = [UIColor redColor]; } return _vertLine; } @end