Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get rect for UICollectionView

I want to locate the frame of section header in UICollectionView. I have a similar situation for UITableView, and for that, I was able to get its rect by doing:

 CGRect rect = [self.tableView rectForHeaderInSection:section];

Is there a way to get the same result in UICollectionView? Thanks!

like image 414
tsuyoski Avatar asked Dec 31 '25 04:12

tsuyoski


1 Answers

Sorry, guys. It was actually easy.

 NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
 UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath];
 CGRect rect = [attributes frame];
like image 135
tsuyoski Avatar answered Jan 01 '26 17:01

tsuyoski