How to determine height of UICollectionView with FlowLayout

Whoa! For some reason, after hours of research, I now found a pretty easy answer to my question: I was completely searching in the wrong place, digging through all the documentation I could find on UICollectionView. The simple and easy solution lies in the underlying layout: Just call collectionViewContentSize on your myCollectionView.collectionViewLayout property and you … Read more

UICollectionView current visible cell index

indexPathsForVisibleItems might work for most situations, but sometimes it returns an array with more than one index path and it can be tricky figuring out the one you want. In those situations, you can do something like this: CGRect visibleRect = (CGRect){.origin = self.collectionView.contentOffset, .size = self.collectionView.bounds.size}; CGPoint visiblePoint = CGPointMake(CGRectGetMidX(visibleRect), CGRectGetMidY(visibleRect)); NSIndexPath *visibleIndexPath = … Read more

UICollectionView inside a UITableViewCell — dynamic height?

The right answer is YES, you CAN do this. I came across this problem some weeks ago. It is actually easier than you may think. Put your cells into NIBs (or storyboards) and pin them to let auto layout do all the work Given the following structure: TableView TableViewCell CollectionView CollectionViewCell CollectionViewCell CollectionViewCell […variable number … Read more

UIRefreshControl on UICollectionView only works if the collection fills the height of the container

Try this: self.collectionView.alwaysBounceVertical = YES; Complete code for a UIRefreshControl UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; refreshControl.tintColor = [UIColor grayColor]; [refreshControl addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged]; [self.collectionView addSubview:refreshControl]; self.collectionView.alwaysBounceVertical = YES;

How to set cell spacing and UICollectionView – UICollectionViewFlowLayout size ratio?

Add these 2 lines layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 0 So you have: // Do any additional setup after loading the view, typically from a nib. let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0) layout.itemSize = CGSize(width: screenWidth/3, height: screenWidth/3) layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 0 collectionView!.collectionViewLayout = … Read more

How to set UICollectionViewCell Width and Height programmatically

Use this method to set custom cell height width. Make sure to add this protocols UICollectionViewDelegate UICollectionViewDataSource UICollectionViewDelegateFlowLayout If you are using swift 5 or xcode 11 and later you need to set Estimate Size to none using storyboard in order to make it work properly. If you will not set that than below code … Read more

UICollectionView, full width cells, allow autolayout dynamic height?

1. Solution for iOS 13+ With Swift 5.1 and iOS 13, you can use Compositional Layout objects in order to solve your problem. The following complete sample code shows how to display multiline UILabel inside full-width UICollectionViewCell: CollectionViewController.swift import UIKit class CollectionViewController: UICollectionViewController { let items = [ [ “Lorem ipsum dolor sit amet.”, “Lorem … Read more

Creating a UICollectionView programmatically

Header file:– @interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout> { UICollectionView *_collectionView; } Implementation File:– – (void)viewDidLoad { [super viewDidLoad]; self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; _collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; [_collectionView setDataSource:self]; [_collectionView setDelegate:self]; [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@”cellIdentifier”]; [_collectionView setBackgroundColor:[UIColor redColor]]; [self.view addSubview:_collectionView]; // Do any additional setup after loading the view, typically … Read more

UICollectionView spacing margins

You can use the collectionView:layout:insetForSectionAtIndex: method for your UICollectionView or set the sectionInset property of the UICollectionViewFlowLayout object attached to your UICollectionView: – (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(top, left, bottom, right); } or UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init]; [aFlowLayout setSectionInset:UIEdgeInsetsMake(top, left, bottom, right)]; Updated for Swift 5 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: … Read more

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