如何自定义CollectionView中每个元素的大小和间距
2015-11-18 16:50
561 查看
问题: 让每个元素大小变为104 x 104
Step 1:
在你的视图控制器头文件中实现UICollectionViewFlowLayout协议
eg:
Step 2:
设置每个单元格的大小
eg:
- (CGSize) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(104.0f, 104.0f);
}
Step 3:
设置单元格间的横向间距
eg:
Step 4:
设置纵向的行间距
eg:
step 5:
通过调整inset使单元格顶部和底部都有间距(inset次序: 上,左,下,右边)
eg:
Step 1:
在你的视图控制器头文件中实现UICollectionViewFlowLayout协议
eg:
@interface XXViewController : UICollectionViewController<UICollectionViewFlowLayout> ... @end
Step 2:
设置每个单元格的大小
eg:
- (CGSize) collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(104.0f, 104.0f);
}
Step 3:
设置单元格间的横向间距
eg:
- (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 2.0f; }
Step 4:
设置纵向的行间距
eg:
- (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 2.0f; }
step 5:
通过调整inset使单元格顶部和底部都有间距(inset次序: 上,左,下,右边)
eg:
- (UIEdgeInsets) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(2.0f, 0.0f, 2.0f, 0.0f); }
相关文章推荐
- mysql
- 数据预处理:PCA,SVD,whitening,normalization
- android adb
- easyui只选择年份月份的插件---SimpleCanleder
- Linux下MongoDB安装及使用
- iOS中的observer(观察者设计模式)swift版
- Android:Calling startActivity() from outside of an Activity 错误
- freescale imx6 products
- 在一串字符中匹配出4个连续的数字
- java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to java.sql.Connection异常问题解决
- oracle 11g 完全卸载
- PostgreSQL 性能测试工具
- Android Studio模块化编程实践之aar
- Linux内核4级页表的演进
- impala keepalived+haproxy
- java.lang.ClassNotFoundException: javax.persistence.Cacheable
- Python学习指南
- 【179】IDL 读写 NetCDF 文件
- Hadoop学习笔记—2.不怕故障的海量存储:HDFS基础入门
- 迅速增强公司信息安全性的10大划算方式