iOS UICollectionView prototype cell size property ignored

后端 未结 9 2023
花落未央
花落未央 2021-01-30 19:51

I\'m using a UICollectionView with two prototype cells. The prototype cells have different widths and contain different controls (image view and web view). I\'m definitely ret

9条回答
  •  情深已故
    2021-01-30 20:20

    Try to use UICollectionViewDelegateFlowLayout method. In Xcode 11 or later, you need to set Estimate Size to none from Storyboard.

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: 
    UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
          let padding: CGFloat =  170
          let collectionViewSize = advertCollectionView.frame.size.width - padding
          return CGSize(width: collectionViewSize/2, height: collectionViewSize/2)
    }
    

提交回复
热议问题