No Description

FKCirDetailZanCell.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // FKCirDetailZanCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/6/14.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCirDetailZanCell.h"
  9. #import "FKCircleDetailViewModel.h"
  10. @interface FKCirDetailZanCell ()
  11. @property (nonatomic, strong) NSArray *imageViews;
  12. @property (nonatomic, strong) UIView *topLine;
  13. @property (nonatomic, strong) UILabel *countLabel;
  14. @end
  15. @implementation FKCirDetailZanCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. [self addAllSubviews];
  19. self.selectionStyle = UITableViewCellSelectionStyleNone;
  20. self.contentView.backgroundColor = [UIColor whiteColor];
  21. }
  22. return self;
  23. }
  24. - (void)addAllSubviews{
  25. [self.contentView addSubview:self.topLine];
  26. [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.equalTo(self.contentView).offset(15);
  28. make.right.top.equalTo(self.contentView);
  29. make.height.mas_equalTo(0.5);
  30. }];
  31. NSInteger maxCount = [self maxCount];
  32. CGFloat margin = [self commonMargin];
  33. NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:maxCount];
  34. UIImageView *frontImgView = nil;
  35. for (int i = 0; i < maxCount; i++) {
  36. UIImageView *imageView = [self createCommonImgView];
  37. [self.contentView addSubview:imageView];
  38. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. if (i == 0){
  40. make.left.equalTo(self.contentView).offset(15);
  41. make.centerY.equalTo(self.contentView);
  42. make.width.height.mas_equalTo(30);
  43. }else {
  44. make.left.equalTo(frontImgView.mas_right).offset(margin);
  45. make.centerY.equalTo(self.contentView);
  46. make.width.height.mas_equalTo(30);
  47. }
  48. }];
  49. [arrayM addObject:imageView];
  50. frontImgView = imageView;
  51. }
  52. self.imageViews = arrayM;
  53. }
  54. - (CGFloat)commonMargin{
  55. NSInteger maxCount = [self maxCount];
  56. CGFloat margin = (UISCREENWIDTH - 30 - 30 * maxCount) / (maxCount - 1);
  57. return margin;
  58. }
  59. - (NSUInteger)maxCount{
  60. if (UISCREENWIDTH <= 320) return 8;
  61. return 9;
  62. }
  63. - (UIImageView *)createCommonImgView{
  64. UIImageView *imageView = [[UIImageView alloc]init];
  65. imageView.contentMode = UIViewContentModeScaleAspectFit;
  66. imageView.layer.cornerRadius = 15;
  67. imageView.layer.masksToBounds = YES;
  68. return imageView;
  69. }
  70. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  71. if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]) {
  72. FKCircleDetailViewModel *cirViewModel = (FKCircleDetailViewModel *)viewModel;
  73. [self configWithPicArray:cirViewModel.dataItem.realZanPicArray totalCount:cirViewModel.dataItem.likeCount];
  74. }
  75. }
  76. - (void)configWithPicArray:(NSArray *)picArray totalCount:(NSInteger)totalCount{
  77. if (!picArray.count) return;
  78. self.countLabel.text = [NSString stringWithFormat:@"%ld", (long)totalCount];
  79. [self.countLabel removeFromSuperview];
  80. for (int i = 0; i < self.imageViews.count; i++) {
  81. UIImageView *imageView = self.imageViews[i];
  82. imageView.image = nil;
  83. if (i == picArray.count){
  84. [self.contentView addSubview:self.countLabel];
  85. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.center.equalTo(imageView);
  87. make.size.equalTo(imageView);
  88. }];
  89. }else if (i == self.imageViews.count - 1){
  90. if (!self.countLabel.superview){
  91. [self.contentView addSubview:self.countLabel];
  92. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.center.equalTo(imageView);
  94. make.size.equalTo(imageView);
  95. }];
  96. }
  97. }else if (i < picArray.count){
  98. UIImageView *imageView = self.imageViews[i];
  99. // [imageView setImageWithURL:picArray[i] cdnWidth:30];
  100. [imageView setImageWithURL:picArray[i] placeholderImage:nil width:30 height:30];
  101. }
  102. }
  103. }
  104. #pragma mark - property
  105. - (UIView *)topLine{
  106. if (_topLine == nil) {
  107. _topLine = [[UIView alloc]init];
  108. _topLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
  109. }
  110. return _topLine;
  111. }
  112. - (UILabel *)countLabel{
  113. if (_countLabel == nil) {
  114. _countLabel = [[UILabel alloc]init];
  115. _countLabel.font = [UIFont systemFontOfSize:12];
  116. _countLabel.textColor = UIColorFromRGB(0x9B9B9B);
  117. _countLabel.backgroundColor = UIColorFromRGB(0xe2e2e2);
  118. _countLabel.layer.cornerRadius = 15;
  119. _countLabel.layer.masksToBounds = YES;
  120. _countLabel.textAlignment = NSTextAlignmentCenter;
  121. }
  122. return _countLabel;
  123. }
  124. @end