UICollectionView Set number of columns

With Swift 5 and iOS 12.3, you can use one the 4 following implementations in order to set the number of items per row in your UICollectionView while managing insets and size changes (including rotation). #1. Subclassing UICollectionViewFlowLayout and using UICollectionViewFlowLayout‘s itemSize property ColumnFlowLayout.swift: import UIKit class ColumnFlowLayout: UICollectionViewFlowLayout { let cellsPerRow: Int init(cellsPerRow: Int, … Read more

Specifying one Dimension of Cells in UICollectionView using Auto Layout

It sounds like what you are asking for is a way to use UICollectionView to produce a layout like UITableView. If that’s really what you want, the right way to do this is with a custom UICollectionViewLayout subclass (maybe something like SBTableLayout). On the other hand, if you’re really asking if there is a clean … Read more

UICollectionView auto scroll to cell at IndexPath

New, Edited Answer: Add this in viewDidLayoutSubviews SWIFT override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() let indexPath = IndexPath(item: 12, section: 0) self.collectionView.scrollToItem(at: indexPath, at: [.centeredVertically, .centeredHorizontally], animated: true) } Normally, .centerVertically is the case ObjC -(void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:12 inSection:0]; [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically | UICollectionViewScrollPositionCenteredHorizontally animated:NO]; } Old answer working for … Read more

Long press gesture on UICollectionViewCell

Objective-C In your myCollectionViewController.h file add the UIGestureRecognizerDelegate protocol @interface myCollectionViewController : UICollectionViewController<UIGestureRecognizerDelegate> in your myCollectionViewController.m file: – (void)viewDidLoad { // attach long press gesture to collectionView UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; lpgr.delegate = self; lpgr.delaysTouchesBegan = YES; [self.collectionView addGestureRecognizer:lpgr]; } -(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateEnded) { return; } CGPoint p … Read more

How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?

I would suggest the following: Add a height constraint to your collection view. Set its priority to 999. Set its constant to any value that makes it reasonably visible on the storyboard. Change the bottom equal constraint of the collection view to greater or equal. Connect the height constraint to an outlet. Every time you … Read more

UICollectionView’s cellForItemAtIndexPath is not being called

For those who stumble here later…. the reason: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath was not being called was because of the itemSize for the collectionViewFlowLayout’s height was too big. [self.myCollectionViewFlowLayout setItemSize:CGSizeMake(320, 548)]; If I change the height to 410, it will execute cellForItemAtIndexPath.

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