实现的效果如下:

主要实现代码如下:

 //
// 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. Oracle 单列去重 显示单行所有列数据

    问题:test_table 表中有 a,b,c 三个字段,求根据字段a 去除重复数据,得到去重后的整行数据 根据mysql的经验尝试以下方法均失败 1.使用 distinct 关键字 (oracle查 ...

  2. drf 第一节

    drf django-restframework ''' 1.接口:接口的概念.数据接口文档.接口规范(restful).Postman接口测试工具 2.drf请求生命周期 - CBV 3.drf的基 ...

  3. Qt 解释JSon数据

    jsondata={"cmd":"meetingmemberlist","memberinfos":[{"name":& ...

  4. 【Android-布局复用】 多个界面复用一个布局文件(一)

    1.layout_common.xml 复用的布局文件 <?xml version="1.0" encoding="utf-8"?> <!-- ...

  5. DNS服务基础

    DNS服务器的功能 – 正向解析:根据注册的域名查找其对应的IP地址 – 反向解析:根据IP地址查找对应的注册域名(不常用) NS(声明DNS记录) A(正向解析记录) CNAME(解析记录别名) 安 ...

  6. 【leetcode】1290. Convert Binary Number in a Linked List to Integer

    题目如下: Given head which is a reference node to a singly-linked list. The value of each node in the li ...

  7. React组件式编程Demo-用户的增删改查

    1.项目结构 项目是基于webpack4, 参考 创建基本的webpack4.x项目 2.页面效果 初始化效果

  8. react-native-page-listview使用方法(自定义FlatList/ListView下拉刷新,上拉加载更多,方便的实现分页)

    react-native-page-listview 对ListView/FlatList的封装,可以很方便的分页加载网络数据,还支持自定义下拉刷新View和上拉加载更多的View.兼容高版本Flat ...

  9. TextRCNN 文本分类 阅读笔记

    TextRCNN 文本分类 阅读笔记 论文:recurrent convolutional neural networks for text classification 代码(tensorflow) ...

  10. free 内存检测

    free打印出的内存信息主要分为两种,一种是安装的内存,一种是用磁盘虚拟的内存,就是这里的Swap,相信装过Linux系统的同学肯定不陌生交换分区,这里Swap大小就是我们分区的时候分配的大小. 下面 ...