UICollectionView Cell Spacing based on device screen size

后端 未结 5 1764
眼角桃花
眼角桃花 2020-12-08 01:24

I have implemented a UICollectionView, the cell size is w90 h90. When i run it on iPhone 6 i get the proper spacing between cell but when i do it on iPhone 5s i get more sp

5条回答
  •  孤城傲影
    2020-12-08 01:44

    Objective-c example:

    use this function

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
         return CGSizeMake(Your desired width, Your desired height);    
        // example: return CGSizeMake(self.view.frame.size.width-20, 100.f);
    }
    

提交回复
热议问题