Uicollection view dynamic height but fixed width

与世无争的帅哥 提交于 2020-03-05 00:23:37

问题


I am working with UICollectionView I have 4 different kind of cells. Every cell is designed in xib file . when i load them in collection view it goes out of screen. i don't know why it is happening. Some cells have fixed height while some have dynamic height (depends on data coming from API). So is there any possible way to solve this issue. i have tried Estimate size automatic to dynamic

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)}

}


回答1:


try this!

let screenWidth = self.CollecionView.frame.width


来源:https://stackoverflow.com/questions/60209613/uicollection-view-dynamic-height-but-fixed-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!