集合视图单元格宽度会导致额外的间距

时间:2017-11-25 01:26:26

标签: ios swift xcode

我正在创建一个与视图宽度相同的集合视图,以及一个设置的高度。对于集合视图中的单元格,我希望有两列是两列,每个单元格是屏幕宽度的一半。我在iPhone 8的故事板中设计了它,它看起来很好。当我在iPhone 8 plus上查看时,右栏左侧有一些额外的填充,如下所示。

Extra padding on iPhone 8+

我想摆脱那个填充。我通过编写下面的代码尝试了这一点,但它似乎没有用

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        // Place content into hashtag cells
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "hashtagCell", for: indexPath) as! TrendingTagsCollectionViewCell
        cell.delegate = self
        cell.hashtagText = hashtags[indexPath.row]
        cell.frame.size.width = view.frame.width / 2
        return cell
}


extension GlobeTableViewController: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0.0
}
}

0 个答案:

没有答案
相关问题