UICollectionViewFlowLayout sections as columns rather than rows - ios

I'm trying to create a UICollectionView of two columns (of potentially different lengths) with the property that when a cell is deleted the cells below (rather than the cells to the right) move up to take its place. I have considered customising the layout using layoutAttributesForElementsInRect etc but don't want to do this if there's an easier way.
Basically all I need is the transpose of the standard FlowLayout with each section a new column instead of a new row. Any advice would be much appreciated.

It is not possible using UICollectionView without customizing the collection view layout based on your needs. UICollectionViewFlowLayout is a line breaking layout that means, it places all your cells along a line and break that line to the bounds of the collection view one by one. So you can place two cells in a row by adjusting the cell size and section insects. Even though it wont allow you adjust the cell during the deletion as your need. Obviously the adjacent cell will take place the position when deleting a cell. Can you go with two collection views side by side instead of one??

Related

UITableView cells on the same row

as I say in the title, I'd like to display two or more cells on the same row. I have every cell with a UILabel inside. The labels can have changing width depending on user's input. I'd like to fill a row with many labels as I can. Can someone give me some advice on how to do it? Thanks.
Short answer: You can't. Slightly longer answer: Use a collection view.
Table views are designed to show a single column of cells.
You can't make a table view contain multiple cells in a row.
You could probably create a view controller that had side-by-side table views inside it, but it would be awkward and hard to use, and the table views would scroll independently of each other.
If you want multiple cells on the same row, you want a collection view. A collection view is similar to, but more flexible than, a table view.
I would consider using a horizontal UIStackView to achieve what you're trying to do. Depends on how dynamic and changeable you need it to be.

iOS - Add border around a collection view cell and a view under it

There is a collection view cell and a view of the same size right under it.
Instead of separately adding two circle borders for both the cell and the view, I want to add one for them together (forming a rounded rectangle)
Is this possible?
If yes, how to handle the scrolling of the collection view?
Yes it is possible but tricky.
I'd suggest you really try to combine it into one cell to avoid lots of headaches.
If you can not then you need to toy with the collection view layout to get your cell to line up correctly with the view underneath and you need to figure out the scrolling as you indicate.
I've sometimes had to use two consecutive collection view cells that needed to align and it was terrible to get it right, thus I suggest try to solve this problem using just a single cell. FWIW the last cell in a collection view often shifts slightly compared to the others so I've sometimes added a blank cell last just so my second to last will align correctly.

Best approach to achieve this grid layout on iOS

A question for the UICollectionView experts.
Imagine a collection view that looks like a table view (full width cells), and when you tap on one of them, new cells are inserted underneath that cell that are square cells, say half the width of the collection view, in 2 columns. Tapping the header again would appear to collapse the section.
Keeping in mind that I’m trying to use UICollectionViewFlowLayout instead of a custom UICollectionView.
Would you:
A) implement the tableview style cells as collection view supplementary views (headers), with a gesture recogniser that inserts the square cells?; or
B) implement the tableview style cells as one cell type, and the square cells as another cell type?; or
C) something else?
Personally I would go with option A. In the situation you're describing the full width item is really a section header that's function is to show/hide it's sections's cells.
From a data structure standpoint this is much easier to maintain with this approach. It can be handled with an array of arrays.
If they were all cells it would most likely be one large array, and would be more difficult to make the distinction between a full width cell and the half width cells.

UICollectionView two cells in a single row

I am trying to layout a vertical scrolling collection view cells to layout like this
When I tried to size the cells like that it made the bottom right one go onto the next line instead of group them together.
Take a look at the UICollectionViewLayout class. There you should find methods you need to achieve your desired look.
https://developer.apple.com/library/prerelease/tvos/documentation/UIKit/Reference/UICollectionViewLayout_class/index.html

Changing frame of one of two sections of UICollectionView - ios

I am trying to configure my CollectionView to have one section be differently sized than the others. I have two sections. Lower part should show a number of cells simultaneously and the upper section should only show one cell at a time but be scrollable to reveal more cells one by one.
I tried to play with the .frame property of the CollectionView but obviously it is not the right approach as it changes the appearance of the whole view.
I also tried to retrieve the FlowLayout object and see if I can get it from there. Did not find a way.
Neither the section Insets are the answer so far ...
It is simple to use two uicollectionviews for upper and lower section, instead of using only one.

Resources