To show only two columns in a collectionView i am using this piece of code
let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
layout.minimumInteritemSpacing = 4
layout.itemSize = CGSize(width:(self.collectionView.frame.size.width - 10)/2,height: (self.collectionView.frame.size.height)/3)
but it is only showing properly on 5s, not on every iphone. please help.
i want to show my view controller like this image. please help anyone
I have following code which I have implemented to display two column in collection view.
Add
UICollectionViewDelegateFlowLayout
’s following method method:Where 30 stand for left, right and middle space between cell.
i.e Cell should be add 10 pixel on left Side, 10 pixel on right side and 10 pixel in between two cell.
Select you
collectionview
from storyboard and from Size Inspector set following minimum spacing.I hope this will fix you issue.
Let me know if any query.
Make sure your protocol confirms to your ViewController,
And set flow layout to your collectionview object
In viewDidLoad
And implement following methods
You must be missing
UICollectionViewDelegateFlowLayout
Try this and see:
// Interface Design
Result:
add this code to viewDidLoad. change height according to you.
try this!