如何根据图像自定义集合视图单元格
Posted
技术标签:
【中文标题】如何根据图像自定义集合视图单元格【英文标题】:How to customise collection view cell as per the images 【发布时间】:2015-04-22 13:31:21 【问题描述】:下面是我的代码。我可以加载,但两个单元格之间有一些空间。如何避免。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
return [dashBoard_img count];
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
UIImage * image = [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];
return image.size;
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
return UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0);
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewFlowLayout *)collectionViewLayout
interitemSpacingForSectionAtIndex:(NSInteger)section
return 2.0;
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
FMMosaicCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[FMMosaicCellView reuseIdentifier] forIndexPath:indexPath];
// float horizontal = 8.0;
//float vertical = 15.0;
UIImage *image = [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];
cell.imageView.frame = CGRectMake(cell.imageView.frame.origin.x, cell.imageView.frame.origin.y, image.size.width, image.size.height);
// cell.imageView.frame = CGRectMake(horizontal, cell.imageView.frame.origin.y, image.size.width, image.size.height);
cell.imageView.image = image;
return cell;
【问题讨论】:
【参考方案1】:也许你必须避免插入。
输入:return UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
代替:return UIEdgeInsetsMake(5.0, 5.0, 5.0, 5.0);
【讨论】:
【参考方案2】:使用这个演示......
SWIFT:
http://www.raywenderlich.com/78550/beginning-ios-collection-views-swift-part-1
目标 C:
https://github.com/eoghain/RBCollectionViewBalancedColumnLayout
【讨论】:
以上是关于如何根据图像自定义集合视图单元格的主要内容,如果未能解决你的问题,请参考以下文章
当在顶部添加新帖子时,UICollectionView 单元格自定义 FlowLayout 中断