简体   繁体   中英

UICollectionView Horizontal - Can't set height less than around 100?

I implemented a UICollectionView with horizontal scrolling. My cells are simply thumbnails (UIImageView) with a size of 50x50.

    let cvLayout = UICollectionViewFlowLayout()

    cvLayout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
    cvLayout.itemSize = CGSize(width: 50, height: 50)
    cvLayout.scrollDirection = .horizontal

All works fine, as long as the UICollectionView's height is above ca. 100. If I set its height any lower, the images don't appear anymore and the view looks messed up. I tried playing around with all available settings, nothing changes this.

Does the UICollectionView have a minimum height requirement or is this something I could solve with a Custom Layout?

I appreciate any hint!

Grasping a straws a little unless you update the question for more detail. I am going to say it is one of two things. But most likely the first.

1) You build your layout like in the current question but you never assign it.

            let cvLayout = UICollectionViewFlowLayout()         
            cvLayout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
            cvLayout.itemSize = CGSize(width: 50, height: 50)
            cvLayout.scrollDirection = .horizontal
            //possibly not assigning it
            collectionView.collectionViewLayout = cvLayout

2) you don't have constraints on your imageview but my guess is this is not the case.

Again, I am just taking a stab at it. If you comment below if neither of these fix the issue I will update the answer provided I have more information. I can set the height to 50 and it fits perfect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM