Cell中实现多图展示
实现的效果如下:

主要实现代码如下:
//
// 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中实现多图展示的更多相关文章
- 关于cell中添加子视图 复用重叠问题的解决方法
问题本质: 因为你要添加的子视图并不是在自定义的cell中实现的,而是根据系统给的UITableViewCell这个类创建的实例,每次进图 cellForRow方法都会创建一个cell,每次都要创 ...
- iOS 超大高清图展示策略 TileLayer 及 levelsOfDetailBias 分析
本次分析针对当下流行的中国地图图片处理,1亿像素,就是下面这张: 原图尺寸:11935x8554 文件大小:22.1MB 原始加载方式 首先,我们尝试一下直接加载的方式,看看效果会有多恐怖 效果请看下 ...
- 基于Echarts的股票K线图展示
发布时间:2018-10-31 技术:javascript+html5+canvas 概述 基于echarts的股票K线图展示,只需引用单个插件,通过简单配置,导入数据,即可实现炫酷复杂的K线 ...
- SharePoint中使用Visio Service展示业务数据
SharePoint中可以通过Visio Service可以在浏览器中查看Visio图,功能部署到系统中,一切安好. 而现实总是很折磨人,使用该功能后,相关使用者随后提出,Visio图能否与我的业务数 ...
- Bootstrap中轮播图
Bootstrap中轮播图插件叫作Carousel,为了清晰的表明每个标签在这里是什么意思,我把解释写在了下面的代码中. <!-- 以下容器就是整个轮播图组件的整体, 注意该盒子必须加上 cla ...
- flask+layui+echarts实现前端动态图展示数据
效果图: 该效果主要实现一个table展示数据,并在下方生成一个折线图. 实现方式: 1.首先需要对表格进行一个数据加载,这里用到了layui的table.render,具体用法可以参考 https: ...
- 【】(Git)用动图展示10大Git命令
1.说明 git merge.git rebase.git reset.git revert.git fetch.git pull.git reflog-- 你知道这些 git 命令执行的究竟是什么任 ...
- MindManager中发送导图给别的用户的教程
使用MindManager思维导图的过程中,可以发送当前导图.导图模版或导图主题给其他的Mindjet用户,如果正在进行导图审阅,发送导图时可以使用"供审阅"选项,本文具体为大家讲 ...
- iOS中获取cell中webview的内容尺寸
最近项目中遇到在cell中获取webView的内容的尺寸的需求 实现的思路其实很简单 就是通过执行js 获取尺寸即可 为了后面用着方便我直接封装了一个HTML的cell 起名就叫 STHTMLBase ...
随机推荐
- Tarjan-CV/BCC/SCC算法学习笔记
DFS性质的应用--利用Tarjan算法求割顶.BCC.SCC 整理自<算法竞赛入门经典--训练指南>以及网络 DFS (depth first search)深度优先搜索算法 dfs森林 ...
- 自动化测试环境搭建(appium+selenium+python)
一.需要安装的软件(根据你所需要的版本安装即可,不一定必须按照小编的版本来) JDK:1.8.0_171 Python:3.7.1 node.js:10.13.0 android-sdk_r24.4. ...
- Pycharm中查看内置函数的源码
方法1.鼠标放在函数上,Ctrl+B,看源码 方法2.将光标移动至要查看的方法处,按住ctrl 键,点击鼠标左键,即可查看该方法的源码.
- c#使用 NServiceKit.Redis 封装 RedisHelper
在说StackExchange.Redis 的时候说了,因为我们的项目一直.net4.0不升级,没有办法,我说的不算,哈哈,又查了StackExchange.Redis在.net4.0使用麻烦,所以选 ...
- RHEL8 创建本地YUM存储库
yum 的好处及本地yum的好处不在本文讨论范畴,本文针对rhel8中的新功能yum做简要介绍和配置,在 RHEL 8中分为两个存储库: BaseOS 应用程序流(AppStream) BaseOS中 ...
- crontab踩坑(二):Unit crond.service could not be found.
这是因为Ubuntu上的服务名称是cron不是crond.所以你的命令应该是: sudo service cron start
- 016_linuxC++之_多重继承
(一)代码 #include <iostream> #include <string.h> #include <unistd.h> using namespace ...
- 微软企业库Unity依赖注入
Unity Application Block 1.0系列(4): 方法调用注入(Method Call Injection ) http://www.cnblogs.com/inrie/archiv ...
- Dubbo系列(二)dubbo的环境搭建
dubbo是一个分布式服务框架,提供一个SOA的解决方案.简单的说,dubbo就像在生产者和消费者中间架起了一座桥梁,使之能透明交互.本文旨在搭建一个可供使用和测试的dubbo环境,使用了spring ...
- python之json读写
#将字典转json并写入文件 import json i=3 j=5 a={'a':i,'b':j} js=json.dumps(a) print(js) with open("/Users ...