London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
6 C
New York
Friday, January 31, 2025

ios – Calculating sizeForItemAt for UICollectionViewDelegateFlowLayout


I have been messing round with NASA’s Astronomical Image of the Day API and am making an attempt to indicate the photographs in a group view with three gadgets per row. As anticipated, I am utilizing UICollectionViewDelegateFlowLayout. To outline the scale of every picture, I am utilizing the sizeForItemAt methodology. Excessive stage, I am taking the width of the gathering view, subtracting the padding outlined in different delegate strategies, and dividing that remaining area by the specified variety of columns (3). Surprisingly, it appears my calculations are simply barely off as a result of I solely get 2 columns with a fairly hefty area within the center (and it is not simply that some hypothetical photographs within the center have not completed loading!).

UICollectionView of astronomical photos where there are two columns with a gaping gap in between

Anybody have any concept what’s going on right here? Here is my code:

    extension ApodCollectionViewController: UICollectionViewDelegateFlowLayout {
       fileprivate enum Constants {
           static let numColumns = 3.0
           static let spacing = 10.0
       }

       /// This provides dimension of every merchandise.
       func collectionView(_ collectionView: UICollectionView, format collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
           let availableWidth = collectionView.bounds.width - ((Constants.numColumns+1)*Constants.spacing)
           let widthPer = availableWidth/Constants.numColumns
           return CGSize(width: widthPer, peak: widthPer)
       }

       /// This provides inset round whole assortment view.
       func collectionView(_ collectionView: UICollectionView, format collectionViewLayout: UICollectionViewLayout, insetForSectionAt part: Int) -> UIEdgeInsets {
           return UIEdgeInsets(high: Constants.spacing, left: Constants.spacing, backside: Constants.spacing, proper: Constants.spacing)
       }

       /// This provides area between gadgets (horizontal).
       func collectionView(_ collectionView: UICollectionView, format collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt part: Int) -> CGFloat {
           return Constants.spacing
       }

       /// This provides area between rows (vertical).
       func collectionView(_ collectionView: UICollectionView, format collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt part: Int) -> CGFloat {
           return Constants.spacing
       }
   }

I printed off the collectionView’s bounds’ width to guarantee that wasn’t sudden. It’s actually 402, which is the anticipated variety of factors defining the width of an iPhone 16 Professional display screen.

Anybody have any concepts? Thanks!

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com