Search code examples
iosuicollectionviewcelluicollectionviewcelluniversal

How can I change the size of UI Collection View cells depending on whether it is iPhone or iPad


After creating a universal app on Xcode 6, I have managed to create a UI collection view which displays 2 cells in the width of an iPhone. However when viewed on iPad, it shows 4 cells with lots of padding around the cells.

How can i change the size of cells on an iPad so that 3 cells are shown with minimal padding. I want to leave the iPhone size alone.

So far i have used the storyboard to set the cell size. I have a added a custom cell size of 158pts by 158pts which works perfectly with iPhones. I cannot find this code in the Objective C code. How can I set an individual different size for iPad.

This is what it looks like on iPhone.

https://www.dropbox.com/s/md1sn4z3k78i5s1/iphone.png

and this is what it currently looks like on iPad. The wrong way.

https://www.dropbox.com/s/0x2n9i8v6gvlfnc/ipad.png

I want to get rid of the Grey padding and increase the cell sizes so there are only 3 cells with the same padding as on the iPhone version.

I am a real beginner so any help is much appreciated.


Solution

  • I am answering my own post as I believe that the only way to do this is to use a standard ViewController and place a UICollectionView on top. This way you can add different UICollectionViews for the different Size Classes on Xcode 6.

    At this point you can set different sizes for cells on iPad size classes to iPhones ones.

    There maybe an easier way to use a UICollectionViewController but i am unaware of it, please let me know below.

    EDIT

    I have since found out this can be completed using the UICollectionViewController by using constraints and by increasing the cell when used on iPads by code.