gpt4 book ai didi

ios - ios 中 collectionview 项目的等间距

转载 作者:技术小花猫 更新时间:2023-10-29 11:16:17 25 4
gpt4 key购买 nike

我使用 Collection View Controller 来显示图片,就像在图库中一样。现在我用间距敲了敲。我无法在 Collection View 中设置相等的间距..

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(106.0f, 106.0f);
}

这是我的代码.. 单元格宽度 106imageview 宽度是 104.0f 我在图像左侧设置了 2 点间距现在查看我得到的解决方案如下图所示。 enter image description here

请帮我解决这个问题...

最佳答案

要检查您的集合单元格的外观,您可以在 Storyboard 的帮助下在您的 Storyboard 中进行尝试。首先只是为了检查,像这样在 CollectionViewController 中放置一些静态单元格,以便您的屏幕显示如下:

enter image description here

不,您可以看到那些单元格以及它们之间的间距。在您的情况下,单元格将以不正确的间距显示,如上所示。所以现在打开这个屏幕,打开 Interface Builder 的 Size Inspector。它看起来像这样:

enter image description here

现在您可以在尺寸检查器窗口中看到一些选项。您可以使用最小值调整每个单元格的大小以及它们之间的间距。间距选项。最后,为了左右两侧的间距相等,请使用 Section Insets 选项。当您更改那里的值时,更改将反射(reflect)在您的 Controller View 中。所以如果你想增加/减少一些值,你可以得到一个想法。

希望这对您有所帮助。

关于ios - ios 中 collectionview 项目的等间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24338344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com