Make UICollectionViewCell appear in center of UICollectionView
I have some cells which are dynamically added to the UICollectionView.
What I would like to do is change the inset of these cells so they appear
in the center of the UICollectionView. This is because the more cells that
are added the cell height changes (it is a single Row UICollectionView).
- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
// This method is used to center when one tile is entered else use a
standard no inset
if (self.wordArray.count == 1) {
CGFloat newWidth = (self.tileCollectionView.bounds.size.width -
self.tileCollectionView.bounds.size.height);
return UIEdgeInsetsMake(0, (newWidth / 2), 0, (newWidth/2));
} else {
return UIEdgeInsetsMake(0, 0, 0, 0); // top, left, bottom, right
}
}
How do I get a reference to the UICollectionViewCell current height, for
any of the cells as they are all shaped the same (just their height/width
changes when more added to continue to fit to one row.
Once I have the reference to the cell height, I can add something like:
self.tileCollectionView.bounds.size.height - CELLHEIGHT /2 -- to use as
the inset for the cell.
No comments:
Post a Comment