How to remove the space between Collection View Cell in ios in Iphone 6 and iPhone 6plus?

i has a simple one CollectionView, but it works well in iphone 4u 5and 5s. but when I run in iphone 6and 6plusit looks like

enter image description here

but I want to remove the space between cells in iphone 6and 6 plus. is this property to remove space ?? If this property, tell me.

+4
source share
4 answers
- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    float width = collectionView.frame.size.width / 2;
    return CGSizeMake(width, width);

}

for swift

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
    return CGSizeMake(collectionView.frame.size.width/2, collectionView.frame.size.width/2)
}
+7
source

, , . UICollectionViewFlowLayout UICollectionViewFLowLayoutDelegate

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(HEIGHT, SCREEN_WIDTH/2)
}

Ray Wenderlich : http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12][1]

+2

sizeForItemAtIndexPath delegate

, .

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((collectionView.frame.size.width-15)/2, (collectionView.frame.size.width-15)/2); // here 5 padding between two photos, you give hight and width here
}
+2
CGFloat margin = 5.0;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - margin)/ 2, ([UIScreen mainScreen].bounds.size.width - margin)/ 2);
layout.minimumLineSpacing = margin;
layout.minimumInteritemSpacing = margin;

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];

margin, .

0

Source: https://habr.com/ru/post/1621224/


All Articles