I am writing a calendar based on UICollectionView . One month - one section. The picture shows a view for the iPhone.

Is it possible to display sections in two columns - two sections on one line (display for iPad)?

iphone

    2 answers 2

    Yes, it can be done. You must specify scrollingDirection : [myFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

    • Thanks for the answer, but the solution does not fit. If I show 12 months, then these are 12 sections - 6 rows (vertically) and 2 sections in one row for the width of the screen (horizontally). The scroll should be vertical - Alexey Alybin
    • one
      As an idea to get started, maybe you should do this: a collectionView with two cells in a row, but inside each cell add a new collectionView that will display the month. - Vitali Eller
    • I don’t see any other solutions, so I’ll do it - Alexey Alybin

    There are two ways to arrange sections in 2 columns:

    1. Use nested collections when the cell of the first collection contains the collection as a subview . In this case, we get the following problems:

      • overloaded UI - lags will be noticeable when you first start

      • problems with viewForSupplementaryElementOfKind for the nested collection, since all headers and footers will have the same indexPath

      • problems with cellForItemAtIndexPath for the nested collection - the method will not be called a second time, if there is already a drawn cell with the same indexPath , the cell will simply be copied without updating the data.

    All these problems can be solved programmatically, but it will turn out very ugly and confusing code.

    1. Instead of two sections, make one wide section - cells of two months in one section. You can use empty transparent cells to separate the months.