How to change UICollectionViewCell size programmatically in Swift?

前端 未结 6 1832
你的背包
你的背包 2020-12-07 20:09

I have a UICollectionView with a segmented control to switch between data. But how do I change the UICollectionViewCell size propertie

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 20:53

    first Conform protocol the UICollectionViewDelegateFlowLayout
    
    set width and height  UICollectionViewCell 
    
    UIcollectionViewCell Hight = 300;
    UIcollectionViewCell Width = 380;
    
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize {
          return CGSize(width: CGFloat((380)), height: CGFloat(300))
        }
    

提交回复
热议问题