In my case I want completely remove any spaces between UICollectionViewCell
's. In iPhone 5 it works correct but iPhone 6 and up. Every time I scroll or in the initial load UICollectionView
adds empty space for different rows. I know that could be difference in float values. For example 8.88888881 and 8.88888881.
Green Line is empty space (collection view
background color)
Every time I scroll this line change position.
My code:
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
CGFloat widthAndHeight = [self widthAndHeightForActiveCollectionViewItem];
if (widthAndHeight < 22) {
widthAndHeight = 22;
}
CGFloat result = lroundf(widthAndHeight * self.venueLayoutZoom);
return CGSizeMake(result, result);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsZero;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
For UICollectionViewFlowLayout
I use this because I need to scroll in both directions. Every time size is correct and without any float values. I always tried to modify UICollectionView
width. For example: I have 29 elements in one row and I want it to be 11 px width each. Then I set up width to 319.
And the second question is:
I want to create cell with only right bottom rounded corner like . But again iPhone 6 and up shows me wrong result such as
. (look at this line on top). I want just a smooth colors. But when I scroll left/right it could be normal.
UICollectionViewCell
code:
- (void)prepareForReuse
{
[self.circularLayer removeFromSuperlayer];
}
- (void)awakeFromNib
{
[super awakeFromNib];
[self allocAndAddLayers];
}
- (void)allocAndAddLayers
{
self.circularLayer = [CALayer layer];
[self.layer addSublayer:self.circularLayer];
}
- (void)layoutSubviews
{
[self updateRoundedCorners];
}
- (void)updateRoundedCorners
{
self.circularLayer.bounds = bounds;
self.circularLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
CGRect rect = self.circularLayer.bounds;
CGFloat radius = CGRectGetWidth(rect) / kVenueLayoutCellDefaultCornerRadiusDivider;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.path = maskPath.CGPath;
self.circularLayer.mask = maskLayer;
}