123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // FKCircleLinkCell.m
- // FirstLink
- //
- // Created by jack on 16/6/12.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCircleLinkCell.h"
- #import "FKCircleBestViewModel.h"
- #import "FKMyCircleViewModel.h"
- @interface FKCircleLinkCell ()
- @property (nonatomic, strong) UIView *containerView;
- @property (nonatomic, strong) UIView *cornerCoverView;
- @property (nonatomic, strong) UIView *topLine;
- @property (nonatomic, strong) UIView *bottomLine;
- @property (nonatomic, strong) UIButton *linkBtn;
- @property (nonatomic, strong) UIButton *commentBtn;
- @property (nonatomic, strong) UIButton *seeBtn;
- @end
- @implementation FKCircleLinkCell
- - (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.linkBtn];
- [self.containerView addSubview:self.commentBtn];
- [self.containerView addSubview:self.zanBtn];
- [self.containerView addSubview:self.seeBtn];
- [self.containerView addSubview:self.topLine];
- [self.containerView addSubview:self.bottomLine];
-
- [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsMake(0, 5, 0, 5));
- }];
-
- [self.cornerCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self.containerView);
- make.height.mas_equalTo(8);
- }];
-
- [self.linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.containerView).offset(12);
- make.centerY.equalTo(self.containerView);
- }];
-
- [self.seeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.containerView).offset(- 15);
- make.centerY.equalTo(self.containerView);
- }];
-
- [self.zanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.seeBtn.mas_left).offset(- 15);
- make.centerY.equalTo(self.containerView);
- }];
-
- [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.zanBtn.mas_left).offset(- 15);
- make.centerY.equalTo(self.containerView);
- }];
-
- [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.containerView);
- make.height.mas_equalTo(0.5);
- }];
-
- [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.left.right.equalTo(self.containerView);
- make.height.mas_equalTo(0.5);
- }];
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
-
- if ([viewModel isKindOfClass:[FKCircleBestViewModel class]]) {
-
- FKCircleBestViewModel *bestViewModel = (FKCircleBestViewModel *)viewModel;
- FKCircleContentItem *contentItem = [bestViewModel circleContentItemForIndexPath:indexPath];
-
- BOOL linkHidden = NO;
- if (contentItem.shareItem.productCount <= 1){
- linkHidden = YES;
-
- }else if (contentItem.shareItem.productCount > 1){
- NSString *linkStr = [NSString stringWithFormat:@" %ld件关联商品", (long)contentItem.shareItem.productCount];
- [self.linkBtn setTitle:linkStr forState:UIControlStateNormal];
- }
-
- self.linkBtn.hidden = linkHidden;
- self.topLine.hidden = linkHidden;
-
- NSString *commentStr = [FLStringHelper convertToShortNumStr:contentItem.commentCount];
- NSString *zanStr = [FLStringHelper convertToShortNumStr:contentItem.likeCount];
- NSString *viewStr = [FLStringHelper convertToShortNumStr:contentItem.viewCount];
-
- [self.commentBtn setTitle:[NSString stringWithFormat:@" %@", commentStr] forState:UIControlStateNormal];
- [self.zanBtn setTitle:[NSString stringWithFormat:@" %@", zanStr] forState:UIControlStateNormal];
- [self.seeBtn setTitle:[NSString stringWithFormat:@" %@", viewStr] forState:UIControlStateNormal];
-
- self.zanBtn.selected = contentItem.isLike;
-
- NSInteger rowCount = [bestViewModel numberOfRowsInSection:indexPath.section];
- [self setLastLine:indexPath.row == rowCount - 1];
- }
-
- if ([viewModel isKindOfClass:[FKMyCircleViewModel class]]){
-
- FKMyCircleViewModel *myCircleModel = (FKMyCircleViewModel *)viewModel;
- FKMyCircleContentItem *contentItem = [myCircleModel circleContentItemAtIndex:indexPath.section - 1];
-
- NSString *linkStr = [NSString stringWithFormat:@" %ld件关联商品", (long)contentItem.shareItem.productCount];
-
- NSString *commentStr = [FLStringHelper convertToShortNumStr:contentItem.commentCount];
- NSString *zanStr = [FLStringHelper convertToShortNumStr:contentItem.likeCount];
- NSString *viewStr = [FLStringHelper convertToShortNumStr:contentItem.viewCount];
-
- [self.linkBtn setTitle:linkStr forState:UIControlStateNormal];
- [self.commentBtn setTitle:[NSString stringWithFormat:@" %@", commentStr] forState:UIControlStateNormal];
- [self.zanBtn setTitle:[NSString stringWithFormat:@" %@", zanStr] forState:UIControlStateNormal];
- [self.seeBtn setTitle:[NSString stringWithFormat:@" %@", viewStr] forState:UIControlStateNormal];
-
- self.zanBtn.selected = contentItem.isLike;
- self.cornerCoverView.hidden = YES;
- self.containerView.layer.cornerRadius = 0.0f;
- }
- }
- - (void)setLastLine:(BOOL)lastLine{
- // 最后一行圆角
- self.bottomLine.hidden = NO;
- self.containerView.layer.cornerRadius = 0.0f;
- self.cornerCoverView.hidden = YES;
-
- if (lastLine){
- self.bottomLine.hidden = YES;
- self.containerView.layer.cornerRadius = 4.0f;
- self.cornerCoverView.hidden = NO;
- }
- }
- #pragma mark - property
- - (UIView *)containerView{
- if (_containerView == nil) {
- _containerView = [[UIView alloc]init];
- _containerView.backgroundColor = [UIColor whiteColor];
- }
- return _containerView;
- }
- - (UIView *)cornerCoverView{
- if (_cornerCoverView == nil) {
- _cornerCoverView = [[UIView alloc]init];
- _cornerCoverView.backgroundColor = [UIColor whiteColor];
- }
- return _cornerCoverView;
- }
- - (UIButton *)linkBtn{
- if (_linkBtn == nil) {
- _linkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_linkBtn setImage:[UIImage imageNamed:@"circle_link"] forState:UIControlStateNormal];
- [_linkBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
- _linkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
- _linkBtn.userInteractionEnabled = NO;
- }
- return _linkBtn;
- }
- - (UIButton *)commentBtn{
- if (_commentBtn == nil) {
- _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_commentBtn setImage:[UIImage imageNamed:@"comment_normal"] forState:UIControlStateNormal];
- [_commentBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
- _commentBtn.titleLabel.font = [UIFont systemFontOfSize:13];
- _commentBtn.userInteractionEnabled = NO;
- }
- return _commentBtn;
- }
- - (UIButton *)zanBtn{
- if (_zanBtn == nil) {
- _zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_zanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
- [_zanBtn setImage:[UIImage imageNamed:@"zan_highlight"] forState:UIControlStateSelected];
- [_zanBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
- _zanBtn.titleLabel.font = [UIFont systemFontOfSize:13];
- }
- return _zanBtn;
- }
- - (UIButton *)seeBtn{
- if (_seeBtn == nil) {
- _seeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_seeBtn setImage:[UIImage imageNamed:@"seeBtn"] forState:UIControlStateNormal];
- [_seeBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
- _seeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
- _seeBtn.userInteractionEnabled = NO;
- }
- return _seeBtn;
- }
- - (UIView *)topLine{
- if (_topLine == nil) {
- _topLine = [[UIView alloc]init];
- _topLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
- }
- return _topLine;
- }
- - (UIView *)bottomLine{
- if (_bottomLine == nil) {
- _bottomLine = [[UIView alloc]init];
- _bottomLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
- }
- return _bottomLine;
- }
- @end
|