CollectionView Dynamic cell height swift

前端 未结 3 1820
傲寒
傲寒 2020-12-08 19:37

Im trying to create a collection view with cells displaying string with variable length.

Im using this function to set cell layout:

 func collectionV         


        
3条回答
  •  情话喂你
    2020-12-08 20:08

    In Swift 3, use the below method:

    private func updateCollectionViewLayout(with size: CGSize) {
        var margin : CGFloat = 0;
        if isIPad {
            margin = 10
        }
        else{
            margin = 6
            /* if UIDevice.current.type == .iPhone6plus || UIDevice.current.type == .iPhone6Splus || UIDevice.current.type == .simulator{
             margin = 10
    
             }
             */
        }
        if let layout = menuCollectionView.collectionViewLayout as? UICollectionViewFlowLayout {
            layout.itemSize = CGSize(width:(self.view.frame.width/2)-margin, height:((self.view.frame.height-64)/4)-3)
            layout.invalidateLayout()
        }
    }
    

提交回复
热议问题