Search code examples
iosswiftuikitstoryboardconstraints

The сonstraints do not work on an iPad with collection view


I am using a collection view in a storyboard and I need one ribbon with an image in the center of the screen. Constraints work fine on iPhone, but not iPad. How can this be done? enter image description here


Solution

  • The collectionView cell size is not specified for different screen sizes.

    Use UICollectionViewDelegateFlowLayout's method

    func collectionView(_ collectionView: UICollectionView, 
                          layout collectionViewLayout: UICollectionViewLayout, 
                   sizeForItemAt indexPath: IndexPath) -> CGSize
    

    https://developer.apple.com/documentation/uikit/uicollectionviewdelegateflowlayout/1617708-collectionview