实现的效果如下:

主要实现代码如下:

 //
// 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. layui多图上传实现删除功能

    在使用layui的多图上传时发现没有删除功能 在网上搜索解决办法时有的感觉太复杂有的不符合自己所需要的所以就自己动手 下面附上代码 HTML: <div class="layui-up ...

  2. LVS Nginx和HAproxy的区别,怎么选择最好

    LVS Nginx和HAproxy有什么区别呢? LVS:Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统. Nginx:Nginx是一款轻量级的w ...

  3. Docker清除容器镜像命令:

    # ~/.bash_aliases # Kill all running containers. alias dockerkillall='docker kill $(docker ps -q)' # ...

  4. org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException

    org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method ...

  5. 4-windows启用账户锁定计数器

    1.打开本地策略编辑器 命令:gpedit.msc 2.找到账户锁定策略 3.右键属性,设置登录无效次数 注:这个策略修改完后,不需要重新服务器就能生效

  6. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) D. Delivery Delays (二分+最短路+DP)

    题目链接:https://codeforc.es/gym/101933/problem/D 题意:地图上有 n 个位置和 m 条边,每条边连接 u.v 且有一个距离 w,一共有 k 个询问,每个询问表 ...

  7. Codeforces Round #509 (Div. 2) E. Tree Reconstruction(构造)

    题目链接:http://codeforces.com/contest/1041/problem/E 题意:给出n - 1对pair,构造一颗树,使得断开其中一条边,树两边的最大值为 a 和 b . 题 ...

  8. 编译vim8

    1.获取最新的vim源码 $ wget https://codeload.github.com/vim/vim/tar.gz/v8.1.2256 2.解压缩 $ tar -xvzf vim-8.1.2 ...

  9. Enable file editing in Visual Studio's debug mode

    Visual Studio 使用及调试必知必会 http://www.cnblogs.com/luminji/p/3287728.html How do I enable file editing i ...

  10. 掌握 3 个搜索技巧,在 GitHub 上快速找到实用软件资源

    GitHub 作为目前广大程序猿最大的游乐场,在今年 6 月被 微软 以 75 亿美元价值的微软股票收购,GitHub 再次成为业界讨论的焦点.GitHub 以自由开放的定位吸引了相当多的个人开发者和 ...