ios - UICollectionView iOS8 的问题

标签 ios objective-c uicollectionview uicollectionviewcell

所以我遇到了一个我认为应该 super 简单的最奇怪的问题。这是我的收藏 View

所以.. 如您所见,右侧图像被截断了。现在这是奇怪的部分。这是我的 cellForItemAtIndexPath 方法:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 164, 164)]; // 0 0 164 141
    [cell.contentView addSubview:imageView];
    imageView.image = usersPhotos[indexPath.row];

    return cell;
}

这是我的 Storyboard文件中的 UICollectionView:

注意我在 Storyboard文件中的 collectionViewCell 是 155 x 155,我的 imageView 是 164x164。我这样做是因为出于某种原因我无法弄清楚这一点:

将我的 imageView 设置为 155x155(与单元格大小相同),我们得到如下所示的内容:

那么我在这里做错了什么?很明显我不想要那个白色间距(如上所示)并且我不能再扩展我的 UICollectionViewCell 因为 155 是最大宽度,出于某种原因在 Storyboard上如果你达到 156 的宽度它会使单元格占据整个列, 没有空间留给第二列,这正是我所需要的。

我怎样才能简单地完成这项工作?非常感谢任何帮助,我对为什么会遇到这种行为以及我做错了什么感到非常迷茫。

最佳答案

在 Storyboard中展开 View Controller 并选择“Collection View Flow Layout”,如下所示:

enter image description here

然后在尺寸检查器中找到最小间距,如下所示:

enter image description here

将“For Cells”间距更改为 0。这将允许您在单元格之间没有任何间距地放置单元格,并将单元格大小增加到最大 160(对于 320 的屏幕宽度)。

这将我的 Storyboard布局从这个更改为单元格大小为 160w 的这个:

enter image description here enter image description here

然后,当我运行该应用程序时,所有单元格都在接触:

enter image description here

关于ios - UICollectionView iOS8 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31974211/

相关文章:

ios - UICollectionView dequeueReusableCellWithReuseIdentifier 导致性能问题

swift - Swift 3 中的 UICollectionView + NSFetchedResultsController

ios - swift - UIView 阴影渲染不正确

ios - 对Casting的不完全理解

ios - 登录后自动将用户导航到 Swift 3.0 中的新 ViewController

objective-c - Objective C - 在 while 循环中执行动画

ios - 我应该将什么设置为表中 collectionView 的数据源和委托(delegate)

ios - AVPlayer 和 AVPlayerItem 状态什么时候改变?

objective-c - Mac OS X 下显示桌面/隐藏所有窗口

ios - 使用Objective C在iOS中使用公钥加密或签名字符串