nabiullinas
nabiullinas

Reputation: 1245

Autoresize UICollectionViewCells for different IPhones devices

Some time ago i upgrade xcode and found some changes in storyboard designing. So before, I just create UICollectionView controller with UICollectionViewCell. I set manualy width and height of the cell on it and for all subItems in cell. So, when I run app on different iphones it always have different size, but same spaces between cells. And It also resize cells and content in it. See screenshots for Iphone5S and iphone6enter image description here

enter image description here

But now, With the same settings the result are not the same enter image description here enter image description here

Sa U can see spaces between cells are different in iphone5S and Iphone6. So how can I set regular size for space between cells and make cells bigger for different iphones. My app is only for Iphones with portrait mode

Upvotes: 1

Views: 545

Answers (1)

EmilioPelaez
EmilioPelaez

Reputation: 19912

You can do something like this:

CGFloat margin = 10;
int itemsPerRow = 3;

CGFloat itemSideSize = ([[UIScreen mainScreen] bounds].size.width - itemsPerRow * margin) / 2;
[(UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout setItemSize:CGSizeMake(itemSideSize, itemSizeSize)];
[(UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout setMinimumInteritemSpacing:margin];
[(UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout setMinimumLineSpacing:margin];
[(UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout setSectionInset:UIEdgeInsetsMake(margin, margin, margin, margin)];

Upvotes: 2

Related Questions