实现的效果如下:

主要实现代码如下:

 //
// DetailCell.m
// Floral
//
// Created by 思 彭 on 16/9/21.
// Copyright © 2016年 思 彭. All rights reserved.
// #import "DetailCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+AdjustFrame.h"
#import "ImageCollectionView.h"
#import "ImageCell.h" #define K_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define K_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) @interface DetailCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
NSArray *imagesArray; // 详情多张图片展示
CGFloat imagesHeight;
}
/**
* 头像
*/
@property (weak, nonatomic) IBOutlet UIImageView *avaterImgView;
/**
* 用户名
*/
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
/**
* 描述
*/
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
/**
* 时间
*/
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
/**
* 更多
*/
@property (weak, nonatomic) IBOutlet UIButton *moreButton;
/**
* "更多"按钮被点击
*
* @param sender <#sender description#>
*/
- (IBAction)moreBUttonClick:(id)sender;
/**
* collectionView
*/
@property (weak, nonatomic) IBOutlet UIView *imagesView;
/**
* 赞
*/
@property (weak, nonatomic) IBOutlet UIButton *loveButton;
/**
* 评论
*/
@property (weak, nonatomic) IBOutlet UIButton *commentButton;
/**
* 分享
*/
@property (weak, nonatomic) IBOutlet UIButton *shareButton;
@property (weak, nonatomic) IBOutlet UILabel *morningLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *morningLabelTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomButtonY; @property (nonatomic,strong) ImageCollectionView *collectionView; @end @implementation DetailCell - (void)awakeFromNib { [super awakeFromNib];
// Xcode 8必须自己设置,不然不显示
self.avaterImgView.layer.cornerRadius = ;
self.avaterImgView.layer.masksToBounds = YES;
self.userNameLabel.font = [UIFont systemFontOfSize:];
self.timeLabel.font = [UIFont systemFontOfSize:];
self.contentLabel.font = [UIFont systemFontOfSize:];
self.morningLabel.font = [UIFont systemFontOfSize:];
self.contentLabel.textColor = [UIColor grayColor];
self.timeLabel.textColor = [UIColor grayColor];
self.morningLabel.textColor = [UIColor grayColor];
// 创建collectionView UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
layout.itemSize = CGSizeMake((K_SCREEN_WIDTH - ) / , (K_SCREEN_WIDTH - ) / );
layout.sectionInset = UIEdgeInsetsMake(,,,);
layout.minimumLineSpacing = ;
layout.minimumInteritemSpacing = ;
self.collectionView = [[ImageCollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.backgroundColor = [UIColor clearColor];
[self.imagesView addSubview:self.collectionView]; // 注册cell
[self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ImageCell class]) bundle:nil] forCellWithReuseIdentifier:@"cell"];
} - (void)setModel:(TieZiListModel *)model{ _model = model;
[self.avaterImgView sd_setImageWithURL:[NSURL URLWithString:self.model.customer.headImg] placeholderImage:[UIImage imageNamed:@"p_avatar"]];
self.userNameLabel.text = self.model.customer.userName;
if ([self.model.customer.content isEqualToString:@""]) { self.contentLabel.text = @"这家伙很懒,什么也没留下";
}
else{
self.contentLabel.text = self.model.content;
}
self.morningLabel.text = self.model.content;
[self.loveButton setTitle:[NSString stringWithFormat:@"%ld",self.model.read] forState:UIControlStateNormal];
[self.commentButton setTitle:[NSString stringWithFormat:@"%ld",self.model.comment] forState:UIControlStateNormal];
[self.shareButton setTitle:[NSString stringWithFormat:@"%ld",self.model.share] forState:UIControlStateNormal];
// 判空处理
if (self.model.createDate.length) { NSString *timeString = [self.model.createDate componentsSeparatedByString:@"."][];
self.timeLabel.text = timeString;
}
[self.collectionView reloadData];
self.collectionView.frame = CGRectMake(, self.imagesView.y - , self.imagesView.width, [self getCollectionViewHeight]);
self.model.cellHeight = + + [self getCollectionViewHeight];
} /* 更多按钮被点击 @param sender 点击的按钮
*/
- (IBAction)moreBUttonClick:(id)sender { if ([self.delegate respondsToSelector:@selector(DidClickMoreButton:)]) {
[self.delegate DidClickMoreButton:self];
}
}
- (IBAction)zanButtonClick:(id)sender { [sender setImage:[UIImage imageNamed:@"p_zan-selected"] forState:UIControlStateSelected];
}
- (IBAction)commentClick:(id)sender {
if ([self.delegate respondsToSelector:@selector(DidClickCommentButton:)]) {
[self.delegate DidClickCommentButton:self];
}
}
- (IBAction)shareButtonClick:(id)sender { if ([self.delegate respondsToSelector:@selector(DidClickShareButton:)]) {
[self.delegate DidClickShareButton:self];
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ NSString *attachment = self.model.attachment;
NSArray *imgArray = [attachment componentsSeparatedByString:@","];
return imgArray.count;
} - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSString *attachment = self.model.attachment;
cell.backgroundColor = [UIColor greenColor];
NSArray *imgArray = [attachment componentsSeparatedByString:@","];
cell.imageName = imgArray[indexPath.row];
return cell;
} - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(,,,);
} - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake((K_SCREEN_WIDTH - ) / , (K_SCREEN_WIDTH - ) / );
} - (CGFloat)getCollectionViewHeight{ CGFloat collectionViewHeight = 0.0;
CGFloat height = 0.0;
NSString *attachment = self.model.attachment;
NSArray *imgArray = [attachment componentsSeparatedByString:@","];
if (imgArray.count % != ) { height = imgArray.count / + ;
}
else{
height = imgArray.count / ;
}
collectionViewHeight = height * ((K_SCREEN_WIDTH - ) / ) + ((height + )* );
return collectionViewHeight;
}
@end

写的挺详细哟!!!有问题的可以找我要Demo哟!!

也可以加我的QQ: 1299625033....我们可以一起交流问题,一起学习!!!

Cell中实现多图展示的更多相关文章

  1. 关于cell中添加子视图 复用重叠问题的解决方法

    问题本质:   因为你要添加的子视图并不是在自定义的cell中实现的,而是根据系统给的UITableViewCell这个类创建的实例,每次进图 cellForRow方法都会创建一个cell,每次都要创 ...

  2. iOS 超大高清图展示策略 TileLayer 及 levelsOfDetailBias 分析

    本次分析针对当下流行的中国地图图片处理,1亿像素,就是下面这张: 原图尺寸:11935x8554 文件大小:22.1MB 原始加载方式 首先,我们尝试一下直接加载的方式,看看效果会有多恐怖 效果请看下 ...

  3. 基于Echarts的股票K线图展示

    发布时间:2018-10-31   技术:javascript+html5+canvas   概述 基于echarts的股票K线图展示,只需引用单个插件,通过简单配置,导入数据,即可实现炫酷复杂的K线 ...

  4. SharePoint中使用Visio Service展示业务数据

    SharePoint中可以通过Visio Service可以在浏览器中查看Visio图,功能部署到系统中,一切安好. 而现实总是很折磨人,使用该功能后,相关使用者随后提出,Visio图能否与我的业务数 ...

  5. Bootstrap中轮播图

    Bootstrap中轮播图插件叫作Carousel,为了清晰的表明每个标签在这里是什么意思,我把解释写在了下面的代码中. <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须加上 cla ...

  6. flask+layui+echarts实现前端动态图展示数据

    效果图: 该效果主要实现一个table展示数据,并在下方生成一个折线图. 实现方式: 1.首先需要对表格进行一个数据加载,这里用到了layui的table.render,具体用法可以参考 https: ...

  7. 【】(Git)用动图展示10大Git命令

    1.说明 git merge.git rebase.git reset.git revert.git fetch.git pull.git reflog-- 你知道这些 git 命令执行的究竟是什么任 ...

  8. MindManager中发送导图给别的用户的教程

    使用MindManager思维导图的过程中,可以发送当前导图.导图模版或导图主题给其他的Mindjet用户,如果正在进行导图审阅,发送导图时可以使用"供审阅"选项,本文具体为大家讲 ...

  9. iOS中获取cell中webview的内容尺寸

    最近项目中遇到在cell中获取webView的内容的尺寸的需求 实现的思路其实很简单 就是通过执行js 获取尺寸即可 为了后面用着方便我直接封装了一个HTML的cell 起名就叫 STHTMLBase ...

随机推荐

  1. MAC 环境下搭建HttpRunnerManager平台

    1 . mac pycharm 创建虚拟环境 https://blog.csdn.net/qq_39806105/article/details/96908584 2. mac 环境下搭建HttpRu ...

  2. [NOI2008]假面舞会——数论+dfs找环

    原题戳这里 思路 分三种情况讨论: 1.有环 那显然是对于环长取个\(gcd\) 2.有类环 也就是这种情况 1→2→3→4→5→6→7,1→8→9→7 假设第一条链的长度为\(l_1\),第二条为\ ...

  3. invalid argument "type=bind,source=/tmp/tfserving/serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu," for "--mount" flag: invalid field '' must be a key=value pair

    --mount参数后面不要有空格 空格去掉即可

  4. 配置Anaconda环境

    1. 帮助信息 命令行下执行"conda -h"或“conda --help”可以获得帮助信息: 命令行下执行"conda <argument> -h&quo ...

  5. API接口防止参数篡改和重放攻击

    {近期领导要求我对公司业务的支付类的ocr接口做研究,是否存在支付接口重放攻击,so.....} API重放攻击(Replay Attacks)又称重播攻击.回放攻击.他的原理就是把之前窃听到的数据原 ...

  6. TC做题笔记

    SRM593 Div1Medium--May The Best Pet Win(bitset优化) Description 给出n个元素取值的max.min,把这n个元素分割成两个集合,求如何分割使两 ...

  7. log4j.properties通用配置

    一.Log4j的配置文件分类Log4j支持两种配置文件格式,一种是XML格式的文件,一种是properties(key=value)文件,其中properties格式的配置文件最为常用,其有一个固定的 ...

  8. SpringBoot AOP注解式拦截与方法规则拦截

    AOP的本质还是动态代理对方法调用进行增强. SpringBoot 提供了方便的注解实现自定义切面Aspect. 1.使用需要了解的几个概念: 切面.@Aspect 切点.@Pointcut. 通知. ...

  9. OFDM时域削峰法降峰均比的原理及影响

    以下是对实验室师兄答疑的转述,经加工后的文字不可避免的存在一些噪声,仅供参考: 时域削峰为非线性变换,效果上相当于将时域中功率较大值的信号点,减去一个合适的“抵消”信号点的功率,使其降低到所设置的门限 ...

  10. @ComponentScan什么时候可以不加

    SpringBoot在没配置@ComponentScan的情况下,默认只扫描和主类处于同包下的Class. 主类Application.java: import org.springframework ...