Uicollection视图动态高度但固定宽度

问题描述 投票:0回答:1

我正在使用UICollectionView,我有4种不同类型的单元格。每个单元格都在xib文件中设计。当我将它们加载到收藏夹视图中时,它不在屏幕上。我不知道为什么会这样。有些单元格具有固定的高度,而有些单元格具有动态的高度(取决于来自API的数据)。那么有什么可能的方法来解决这个问题。我已经尝试过自动估计尺寸到动态

override func awakeFromNib() {
    super.awakeFromNib()
    self.contentView.translatesAutoresizingMaskIntoConstraints = false
    let screenwidth = UIScreen.main.bounds.size.width
    widthAnchor.constraint(equalToConstant: screenwidth-20)
}

func setSize () {
    let layout = mainCollection.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)}

} screenshot of how end portion of cell is going out of screen

ios swift uicollectionview uicollectionviewcell
1个回答
0
投票

尝试一下!

let screenWidth = self.CollecionView.frame.width
© www.soinside.com 2019 - 2024. All rights reserved.