No Description

FKCircleLinkCell.m 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // FKCircleLinkCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/6/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCircleLinkCell.h"
  9. #import "FKCircleBestViewModel.h"
  10. #import "FKMyCircleViewModel.h"
  11. @interface FKCircleLinkCell ()
  12. @property (nonatomic, strong) UIView *containerView;
  13. @property (nonatomic, strong) UIView *cornerCoverView;
  14. @property (nonatomic, strong) UIView *topLine;
  15. @property (nonatomic, strong) UIView *bottomLine;
  16. @property (nonatomic, strong) UIButton *linkBtn;
  17. @property (nonatomic, strong) UIButton *commentBtn;
  18. @property (nonatomic, strong) UIButton *seeBtn;
  19. @end
  20. @implementation FKCircleLinkCell
  21. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  22. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  23. [self addAllSubviews];
  24. self.selectionStyle = UITableViewCellSelectionStyleNone;
  25. self.backgroundColor = [UIColor clearColor];
  26. }
  27. return self;
  28. }
  29. - (void)addAllSubviews{
  30. [self.contentView addSubview:self.containerView];
  31. [self.contentView addSubview:self.cornerCoverView];
  32. [self.containerView addSubview:self.linkBtn];
  33. [self.containerView addSubview:self.commentBtn];
  34. [self.containerView addSubview:self.zanBtn];
  35. [self.containerView addSubview:self.seeBtn];
  36. [self.containerView addSubview:self.topLine];
  37. [self.containerView addSubview:self.bottomLine];
  38. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.edges.insets(UIEdgeInsetsMake(0, 5, 0, 5));
  40. }];
  41. [self.cornerCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.right.top.equalTo(self.containerView);
  43. make.height.mas_equalTo(8);
  44. }];
  45. [self.linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.equalTo(self.containerView).offset(12);
  47. make.centerY.equalTo(self.containerView);
  48. }];
  49. [self.seeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.right.equalTo(self.containerView).offset(- 15);
  51. make.centerY.equalTo(self.containerView);
  52. }];
  53. [self.zanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.right.equalTo(self.seeBtn.mas_left).offset(- 15);
  55. make.centerY.equalTo(self.containerView);
  56. }];
  57. [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.right.equalTo(self.zanBtn.mas_left).offset(- 15);
  59. make.centerY.equalTo(self.containerView);
  60. }];
  61. [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.top.left.right.equalTo(self.containerView);
  63. make.height.mas_equalTo(0.5);
  64. }];
  65. [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.bottom.left.right.equalTo(self.containerView);
  67. make.height.mas_equalTo(0.5);
  68. }];
  69. }
  70. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  71. if ([viewModel isKindOfClass:[FKCircleBestViewModel class]]) {
  72. FKCircleBestViewModel *bestViewModel = (FKCircleBestViewModel *)viewModel;
  73. FKCircleContentItem *contentItem = [bestViewModel circleContentItemForIndexPath:indexPath];
  74. BOOL linkHidden = NO;
  75. if (contentItem.shareItem.productCount <= 1){
  76. linkHidden = YES;
  77. }else if (contentItem.shareItem.productCount > 1){
  78. NSString *linkStr = [NSString stringWithFormat:@" %ld件关联商品", (long)contentItem.shareItem.productCount];
  79. [self.linkBtn setTitle:linkStr forState:UIControlStateNormal];
  80. }
  81. self.linkBtn.hidden = linkHidden;
  82. self.topLine.hidden = linkHidden;
  83. NSString *commentStr = [FLStringHelper convertToShortNumStr:contentItem.commentCount];
  84. NSString *zanStr = [FLStringHelper convertToShortNumStr:contentItem.likeCount];
  85. NSString *viewStr = [FLStringHelper convertToShortNumStr:contentItem.viewCount];
  86. [self.commentBtn setTitle:[NSString stringWithFormat:@" %@", commentStr] forState:UIControlStateNormal];
  87. [self.zanBtn setTitle:[NSString stringWithFormat:@" %@", zanStr] forState:UIControlStateNormal];
  88. [self.seeBtn setTitle:[NSString stringWithFormat:@" %@", viewStr] forState:UIControlStateNormal];
  89. self.zanBtn.selected = contentItem.isLike;
  90. NSInteger rowCount = [bestViewModel numberOfRowsInSection:indexPath.section];
  91. [self setLastLine:indexPath.row == rowCount - 1];
  92. }
  93. if ([viewModel isKindOfClass:[FKMyCircleViewModel class]]){
  94. FKMyCircleViewModel *myCircleModel = (FKMyCircleViewModel *)viewModel;
  95. FKMyCircleContentItem *contentItem = [myCircleModel circleContentItemAtIndex:indexPath.section - 1];
  96. NSString *linkStr = [NSString stringWithFormat:@" %ld件关联商品", (long)contentItem.shareItem.productCount];
  97. NSString *commentStr = [FLStringHelper convertToShortNumStr:contentItem.commentCount];
  98. NSString *zanStr = [FLStringHelper convertToShortNumStr:contentItem.likeCount];
  99. NSString *viewStr = [FLStringHelper convertToShortNumStr:contentItem.viewCount];
  100. [self.linkBtn setTitle:linkStr forState:UIControlStateNormal];
  101. [self.commentBtn setTitle:[NSString stringWithFormat:@" %@", commentStr] forState:UIControlStateNormal];
  102. [self.zanBtn setTitle:[NSString stringWithFormat:@" %@", zanStr] forState:UIControlStateNormal];
  103. [self.seeBtn setTitle:[NSString stringWithFormat:@" %@", viewStr] forState:UIControlStateNormal];
  104. self.zanBtn.selected = contentItem.isLike;
  105. self.cornerCoverView.hidden = YES;
  106. self.containerView.layer.cornerRadius = 0.0f;
  107. }
  108. }
  109. - (void)setLastLine:(BOOL)lastLine{
  110. // 最后一行圆角
  111. self.bottomLine.hidden = NO;
  112. self.containerView.layer.cornerRadius = 0.0f;
  113. self.cornerCoverView.hidden = YES;
  114. if (lastLine){
  115. self.bottomLine.hidden = YES;
  116. self.containerView.layer.cornerRadius = 4.0f;
  117. self.cornerCoverView.hidden = NO;
  118. }
  119. }
  120. #pragma mark - property
  121. - (UIView *)containerView{
  122. if (_containerView == nil) {
  123. _containerView = [[UIView alloc]init];
  124. _containerView.backgroundColor = [UIColor whiteColor];
  125. }
  126. return _containerView;
  127. }
  128. - (UIView *)cornerCoverView{
  129. if (_cornerCoverView == nil) {
  130. _cornerCoverView = [[UIView alloc]init];
  131. _cornerCoverView.backgroundColor = [UIColor whiteColor];
  132. }
  133. return _cornerCoverView;
  134. }
  135. - (UIButton *)linkBtn{
  136. if (_linkBtn == nil) {
  137. _linkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  138. [_linkBtn setImage:[UIImage imageNamed:@"circle_link"] forState:UIControlStateNormal];
  139. [_linkBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
  140. _linkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  141. _linkBtn.userInteractionEnabled = NO;
  142. }
  143. return _linkBtn;
  144. }
  145. - (UIButton *)commentBtn{
  146. if (_commentBtn == nil) {
  147. _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  148. [_commentBtn setImage:[UIImage imageNamed:@"comment_normal"] forState:UIControlStateNormal];
  149. [_commentBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
  150. _commentBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  151. _commentBtn.userInteractionEnabled = NO;
  152. }
  153. return _commentBtn;
  154. }
  155. - (UIButton *)zanBtn{
  156. if (_zanBtn == nil) {
  157. _zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  158. [_zanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
  159. [_zanBtn setImage:[UIImage imageNamed:@"zan_highlight"] forState:UIControlStateSelected];
  160. [_zanBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
  161. _zanBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  162. }
  163. return _zanBtn;
  164. }
  165. - (UIButton *)seeBtn{
  166. if (_seeBtn == nil) {
  167. _seeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  168. [_seeBtn setImage:[UIImage imageNamed:@"seeBtn"] forState:UIControlStateNormal];
  169. [_seeBtn setTitleColor:UIColorFromRGB(0x9b9b9b) forState:UIControlStateNormal];
  170. _seeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  171. _seeBtn.userInteractionEnabled = NO;
  172. }
  173. return _seeBtn;
  174. }
  175. - (UIView *)topLine{
  176. if (_topLine == nil) {
  177. _topLine = [[UIView alloc]init];
  178. _topLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
  179. }
  180. return _topLine;
  181. }
  182. - (UIView *)bottomLine{
  183. if (_bottomLine == nil) {
  184. _bottomLine = [[UIView alloc]init];
  185. _bottomLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
  186. }
  187. return _bottomLine;
  188. }
  189. @end