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; … Read more

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> … Read more

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, … Read more

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 … Read more

UICollectionView animating cell size change causes undesired behavior

This is a UICollectionViewFlowLayout bug, but there is a workaround. The problem is that the attributes returned by initialLayoutAttributesForAppearingItemAtIndexPath: have the wrong frames. Specifically, they have the frames of the final, on screen position rather than the initial, off screen position. You just need to override this method and return correct frames. The basic structure … Read more

UICollectionView: One Row or Column

I am guessing you are using the built in Flow Layout. However, for your case, you should make a custom UICollectionView Layout. Make it subclass of UICollectionViewFlowLayout and add this code in the init method: – (id)init { if ((self = [super init])) { self.scrollDirection = UICollectionViewScrollDirectionHorizontal; self.minimumLineSpacing = 10000.0f; } return self; } The … Read more

How to implement horizontally infinite scrolling UICollectionView?

If your data is static and you want a kind of circular behavior, you can do something like this: var dataSource = [“item 0”, “item 1”, “item 2”] func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return Int.max // instead of returnin dataSource.count } func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let … Read more

UICollectionVIew: How can I remove the space on top first cell’s row?

UICollectionView is descendant of UIScrollView class which has contentInset property, setting -20 top inset fixes the problem [self.calendarView setContentInset:UIEdgeInsetsMake(-20, 0, 0, 0)]; However, the problem comes from UIViewController’s automaticallyAdjustsScrollViewInsets property. By documentation: Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)