123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // FKCirDetailZanCell.m
- // FirstLink
- //
- // Created by jack on 16/6/14.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCirDetailZanCell.h"
- #import "FKCircleDetailViewModel.h"
- @interface FKCirDetailZanCell ()
- @property (nonatomic, strong) NSArray *imageViews;
- @property (nonatomic, strong) UIView *topLine;
- @property (nonatomic, strong) UILabel *countLabel;
- @end
- @implementation FKCirDetailZanCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self addAllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- [self.contentView addSubview:self.topLine];
- [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.right.top.equalTo(self.contentView);
- make.height.mas_equalTo(0.5);
- }];
-
- NSInteger maxCount = [self maxCount];
- CGFloat margin = [self commonMargin];
- NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:maxCount];
-
- UIImageView *frontImgView = nil;
- for (int i = 0; i < maxCount; i++) {
- UIImageView *imageView = [self createCommonImgView];
- [self.contentView addSubview:imageView];
-
- [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- if (i == 0){
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView);
- make.width.height.mas_equalTo(30);
- }else {
- make.left.equalTo(frontImgView.mas_right).offset(margin);
- make.centerY.equalTo(self.contentView);
- make.width.height.mas_equalTo(30);
- }
- }];
-
- [arrayM addObject:imageView];
- frontImgView = imageView;
- }
- self.imageViews = arrayM;
- }
- - (CGFloat)commonMargin{
- NSInteger maxCount = [self maxCount];
- CGFloat margin = (UISCREENWIDTH - 30 - 30 * maxCount) / (maxCount - 1);
- return margin;
- }
- - (NSUInteger)maxCount{
- if (UISCREENWIDTH <= 320) return 8;
- return 9;
- }
- - (UIImageView *)createCommonImgView{
- UIImageView *imageView = [[UIImageView alloc]init];
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- imageView.layer.cornerRadius = 15;
- imageView.layer.masksToBounds = YES;
- return imageView;
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]) {
- FKCircleDetailViewModel *cirViewModel = (FKCircleDetailViewModel *)viewModel;
- [self configWithPicArray:cirViewModel.dataItem.realZanPicArray totalCount:cirViewModel.dataItem.likeCount];
- }
- }
- - (void)configWithPicArray:(NSArray *)picArray totalCount:(NSInteger)totalCount{
- if (!picArray.count) return;
-
- self.countLabel.text = [NSString stringWithFormat:@"%ld", (long)totalCount];
- [self.countLabel removeFromSuperview];
-
- for (int i = 0; i < self.imageViews.count; i++) {
-
- UIImageView *imageView = self.imageViews[i];
- imageView.image = nil;
-
- if (i == picArray.count){
-
- [self.contentView addSubview:self.countLabel];
- [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(imageView);
- make.size.equalTo(imageView);
- }];
-
- }else if (i == self.imageViews.count - 1){
-
- if (!self.countLabel.superview){
- [self.contentView addSubview:self.countLabel];
- [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(imageView);
- make.size.equalTo(imageView);
- }];
- }
-
- }else if (i < picArray.count){
- UIImageView *imageView = self.imageViews[i];
- // [imageView setImageWithURL:picArray[i] cdnWidth:30];
- [imageView setImageWithURL:picArray[i] placeholderImage:nil width:30 height:30];
- }
- }
- }
- #pragma mark - property
- - (UIView *)topLine{
- if (_topLine == nil) {
- _topLine = [[UIView alloc]init];
- _topLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
- }
- return _topLine;
- }
- - (UILabel *)countLabel{
- if (_countLabel == nil) {
- _countLabel = [[UILabel alloc]init];
- _countLabel.font = [UIFont systemFontOfSize:12];
- _countLabel.textColor = UIColorFromRGB(0x9B9B9B);
- _countLabel.backgroundColor = UIColorFromRGB(0xe2e2e2);
- _countLabel.layer.cornerRadius = 15;
- _countLabel.layer.masksToBounds = YES;
- _countLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _countLabel;
- }
- @end
|