uicollectionview
UICollectionView wrong contentSize on first load, correct after that
So I was seeing a similar issue where contentSize width was always zero. The simple answer is…there is probably no content in the collectionView yet. That was why it’s content size is zero. I was also noticing that sometimes after calling invalidateLayout on my UICollectionView, I was seeing that self.collectionView.collectionViewLayout.collectionViewContentSize was not the same as …
Invalid update: invalid number of items on UICollectionView
It’s a bug with using insertItemsAtIndexPaths on an empty UICollectionView. Just do this: if (self.birthdays.count == 1) { [self.collectionView reloadData]; } else { [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem: (self.birthdays.count -1) inSection:0]]]; } (Can’t believe this is still broken in iOS8.)
UICollectionView: current index path for page control
You can get the current index by monitoring contentOffset in scrollViewDidScroll delegate it will be something like this -(void)scrollViewDidScroll:(UIScrollView *)scrollView { NSInteger currentIndex = self.collectionView.contentOffset.x / self.collectionView.frame.size.width; }
UICollectionView horizontal paging with 3 items
Edit: Demo link: https://github.com/raheelsadiq/UICollectionView-horizontal-paging-with-3-items After a lot searching I did it, find the next point to scroll to and disable the paging. In scrollviewWillEndDragging scroll to next cell x. – (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { float pageWidth = 480 + 50; // width + space float currentOffset = scrollView.contentOffset.x; float targetOffset = targetContentOffset->x; …
How can I enable/disable section headers in UICollectionView programmatically?
You can either use the collectionView:layout:referenceSizeForHeaderInSection: method of the UICollectionViewDelegateFlowLayout and return CGSizeMake(0,0) or set accordingly the headerReferenceSize of UICollectionViewFlowLayout. Edit: headerReferenceSize is actually the property that storyboard uses to show/hide the headers. I’ve added the relevant lines from the Storyboard file With section checkbox on: <collectionViewFlowLayout key=”collectionViewLayout” minimumLineSpacing=”10″ minimumInteritemSpacing=”10″ id=”xAt-Uo-bMl”> <size key=”headerReferenceSize” width=”50″ height=”50″/></collectionViewFlowLayout> …
UICollection View Flow Layout Vertical Align
Swift 4 with functional oriented approach: class TopAlignedCollectionViewFlowLayout: UICollectionViewFlowLayout { override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { let attributes = super.layoutAttributesForElements(in: rect)? .map { $0.copy() } as? [UICollectionViewLayoutAttributes] attributes? .reduce([CGFloat: (CGFloat, [UICollectionViewLayoutAttributes])]()) { guard $1.representedElementCategory == .cell else { return $0 } return $0.merging([ceil($1.center.y): ($1.frame.origin.y, [$1])]) { ($0.0 < $1.0 ? $0.0 : $1.0, …
How do I define the size of a CollectionView on rotate
Heres my 2 cents – because your item sizes are static why don’t you set the item size on the collectionViewLayout? It will be quicker to do this rather than expecting the collection view to call its delegate method for every cell. viewWillLayoutSubviews can be used for detection of rotation on view controllers. invalidateLayout can …