UICollectionView flowLayout not wrapping cells correctly

There is a bug in UICollectionViewFlowLayout’s implementation of layoutAttributesForElementsInRect that causes it to return TWO attribute objects for a single cell in certain cases involving section insets. One of the returned attribute objects is invalid (outside the bounds of the collection view) and the other is valid. Below is a subclass of UICollectionViewFlowLayout that fixes … Read more

Change UICollectionViewCell size on different device orientations

1) You could maintain and swap out multiple layout objects, but there’s a simpler way. Just add the following to your UICollectionViewController subclass and adjust the sizes as required: – (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { // Adjust cell size for orientation if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { return CGSizeMake(170.f, 170.f); } return CGSizeMake(192.f, 192.f); … Read more

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

Adding rounded corner and drop shadow to UICollectionViewCell

Neither of these solutions worked for me. If you place all your subviews into the UICollectionViewCell content view, which you probably are, you can set the shadow on the cell’s layer and the border on the contentView’s layer to achieve both results. cell.contentView.layer.cornerRadius = 2.0f; cell.contentView.layer.borderWidth = 1.0f; cell.contentView.layer.borderColor = [UIColor clearColor].CGColor; cell.contentView.layer.masksToBounds = YES; … Read more

Why is UICollectionViewCell’s outlet nil?

I am calling self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: “ls”) again. If you are using a storyboard you don’t want to call this. It will overwrite what you have in your storyboard. If you still have the problem check wether reuseIdentifier is same in dequeueReusableCellWithReuseIdentifier and in storyboard.

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

Autoresizing issue of UICollectionViewCell contentView’s frame in Storyboard prototype cell (Xcode 6, iOS 8 SDK) happens when running on iOS 7 only

contentView is broken. It can be also fixed in awakeFromNib ObjC: – (void)awakeFromNib { [super awakeFromNib]; self.contentView.frame = self.bounds; self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } Swift3: override func awakeFromNib() { super.awakeFromNib() self.contentView.frame = self.bounds self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] }

UICollectionView Self Sizing Cells with Auto Layout

This answer is outdated from iOS 14 with the addition of compositional layouts. Please consider updating the new API Updated for Swift 5 preferredLayoutAttributesFittingAttributes renamed to preferredLayoutAttributesFitting and use auto sizing Updated for Swift 4 systemLayoutSizeFittingSize renamed to systemLayoutSizeFitting Updated for iOS 9 After seeing my GitHub solution break under iOS 9 I finally got … Read more

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