Search code examples
iosobjective-ciphoneswiftipad

How to show Collection in iPad but List in iPhone?


I have a requirement to show the Data in Linear Vertical List in iPhone and in Collection/Grid in IPAD

In the iPhone, it should look like

enter image description here

But In Ipad, it should look like

enter image description here

I have already implemented in iPhone through table view but don't know how to show it as grid view in IPAD

Here are my questions

  1. should I have to create the Separate view controller for Ipad if yes then how can I define two view controller one for iPhone and other for iPad

  2. what is the best way to achieve this?

please help me I am trying to implement it but can not find any way.

(Note)Images are copied from Vimeo iTunes app https://itunes.apple.com/us/app/vimeo/id425194759?mt=8


Solution

  • You don't need to create two different controller's for IPAD and IPHONE. Just create one controller with UICollectionView and then use UICollectionViewFlowLayout for your UICollectionView to set layout of UICollectionView according to the device weather it is IPAD or IPHONE Try this solution if you have any doubt pls let us know.

    Try this solution

    UICollectionViewFlowLayout *collectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    [collectionViewFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    self.myCollectionView.collectionViewLayout = collectionViewFlowLayout;
    

    Also you can use multiple properties of UICollectionViewFlowLayout.

    Check this solution and let me know if it works for you.

    Check these links for reference :

    1. https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started

    2. https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest