实现的效果如下:

主要实现代码如下:

 //
// 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. windows安装mysql(5.7.26版本)压缩包

    1.解压安装包,进入文件夹,并创建一个data文件夹! 2.修改 my-default.ini 文件 [mysql] default-character-set=utf8 [mysqld] port ...

  2. Logstash工作原理

    Logstash事件处理有三个阶段:inputs → filters → outputs.是一个接收,处理,转发日志的工具.支持系统日志,webserver日志,错误日志,应用日志,总之包括所有可以抛 ...

  3. linux基础_使用指令

    1.指令运行级别 (0)关机 (1)单用户(找回丢失密码) (2)多用户无网络服务 (3)多用户有网络服务 (4)保留 (5)图形界面 (6)重启 /etc/inittab:系统的运行级别配置之文件 ...

  4. 手摸手教你让Laravel开发Api更得心应手

    https://www.guaosi.com/2019/02/26/laravel-api-initialization-preparation/ 1. 起因 随着前后端完全分离,PHP也基本告别了v ...

  5. No provider available from registry出错

    dubbo+zookeeper进行分布式远程调用时No provider available from registry出错 查看dubbo服务:http://192.168.0.100:8080/d ...

  6. js中showModalDialog的使用

    基本介绍:          showModalDialog()         (IE 4+ 支持)          showModelessDialog()      (IE 5+ 支持)    ...

  7. PHP mysqli_init() 函数

    定义和用法 mysqli_init() 函数初始化 MySQLi 并返回 mysqli_real_connect() 使用的对象. 语法 mmysqli_init();   实例 mysqli_ini ...

  8. 二维FFT,IFFT,c语言实现

    学习DIP第6天 完整内容迁移至http://www.face2ai.com/DIP-2-4-二维FFT-IFFT-c语言实现/ http://www.tony4ai.com/DIP-2-4-二维FF ...

  9. ETL测试场景和测试用例设计

    前段时间做了些数据测试相关的工作,找了些相关方面的资料,也跟一些一线厂的同学聊了下数据测试方面的东西,然后在团队内部形成了一个初级的数据测试的规范流程以及测试需要进行的场景设计和测试用例设计的方案. ...

  10. Python数据抓取(1) —数据处理前的准备

    (一)数据抓取概要 为什么要学会抓取网络数据? 对公司或对自己有价值的数据,80%都不在本地的数据库,它们都散落在广大的网络数据,这些数据通常都伴随着网页的形式呈现,这样的数据我们称为非结构化数据 如 ...