[翻译] FBLikeLayout

  1. 云栖社区>
  2. 博客列表>
  3. 正文

[翻译] FBLikeLayout

游贤明 2016-04-15 14:33:41 浏览486 评论0

摘要: FBLikeLayout   This is an UICollectionView layout inspired by the photo section of facebook. This layout loads squared items with randomic full size items.

FBLikeLayout

 

This is an UICollectionView layout inspired by the photo section of facebook. This layout loads squared items with randomic full size items. It works with standard layout delegate methods. No additional custom methods to be implemented.

这是一个UICollectionView的自动布局文件,灵感来自于Facebook的图片区域效果.这个布局文件加载方形的图片,并自动适应大小.它的代理方法与标准的自动布局代理方法相同.你不需要实现额外的方法.

 

FBLikeLayout

You can use this layout in your project by adding to your podfile:

你可以用CocoaPods来安装,执行以下一句话即可:

pod 'FBLikeLayout'

 

Usage

Just allocate a new FBLikeLayout, then customize the few properties this layout comes with

只需要创建出FBLikeayout,然后定制少量的几个属性即可:

FBLikeLayout *layout = [FBLikeLayout new];

//in this case we want 3 cells per row, maximum. This is also the default value if you do not customize the layout.singleCellWidth property 
CGFLoat cellWidth = (MIN(self.collectionView.bounds.size.width, self.collectionView.bounds.size.height)-self.collectionView.contentInset.left-self.collectionView.contentInset.right-8)/3.0;

layout.minimumInteritemSpacing = 4;
layout.singleCellWidth = cellWidth;
layout.maxCellSpace = 3; //for full size cells, this parameter determines the max cell space

//if you want the items size to be forced in order to have the minimumInteritemSpacing always respected. Otherwise the interitem spacing will be adapted in order to cover the complete row with cells
layout.forceCellWidthForMinimumInteritemSpacing = YES;
layout.fullImagePercentageOfOccurrency = 25; //this percent value determines how many times randomly the item will be full size.

self.collectionView.collectionViewLayout = layout;

Then just implement the UICollectionViewDelegateFlowLayout method:

然后,实现UICollectionViewDelegateFlowLayout就OK啦:

-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

 

用云栖社区APP,舒服~

【云栖快讯】诚邀你用自己的技术能力来用心回答每一个问题,通过回答传承技术知识、经验、心得,问答专家期待你加入!  详情请点击

网友评论

游贤明
文章763篇 | 关注46
关注
移动测试(Mobile Testing)是为广大企业客户和移动开发者提供真机测试服务的云平台... 查看详情
阿里云移动APP解决方案,助力开发者轻松应对移动app中随时可能出现的用户数量的爆发式增长、... 查看详情
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效... 查看详情
阿里云总监课正式启航

阿里云总监课正式启航