UICollectionView 3 column grid, 1px space?? (image included)

前端 未结 4 436
陌清茗
陌清茗 2020-12-31 04:04

I have setup a UICollectionView with a FlowLayout that leaves no space in between cells in either the vertical or horizontal directions.

I have everything working, y

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 04:30

    Here is my solution to issue just make middle cell of width 106 and other two with width 107 in method collectionView layout

    NSInteger numColumns = 3;
    CGSize deviceSize;
    CGFloat width = self.view.frame.size.width / numColumns;
    CGFloat height = width ;
    NSInteger rem = (int)self.view.frame.size.width%numColumns; 
    if(indexPath.row == (1 + numColumns*counter) && rem != 0) {  
    
        deviceSize = CGSizeMake(floor (width), ceil(height));
        counter++;
    }
    else {
    
        deviceSize = CGSizeMake(ceil (width), ceil(height));
    }
    deviceSize = CGSizeMake(deviceSize.width, deviceSize.height);
    

提交回复
热议问题