Collection view Cell layout issue - ios

I am designing an app that has the following layout. I was thinking of having the view as a collectionview.
A and B are a custom collection cells. How would I design the app so that the second and third rows have 2 and 3 cells as shown in the image?
I tried over-riding the sizeForItemAt indexPath method and then calculating the size of each cell based on the row it is in.
Not only it seems a little odd and but the cells don't align properly either.
I tried setting the estimatedItemSize property as well as over-riding preferredLayoutAttributesFitting by following this link.
Is there an easier way to do this UI ? Should I remove colleciton view and go with plain ol tableviews ?
Any help would be much appreciated.

Related

UICollectionView layout with custom layout

Is it possible to create a collection view with an item on the left and two items stacked to the right of it?
Whenever I specify the correct sizes to do this in the sizeForItemAtIndexPath delegate I can only get one item on the right side and the other is displayed in the next row underneath. I know I can do this with custom cells that contain more than one view (top and bottom) but I would like to know if its possible without that. It would be a lot less complex if I could do it without the custom double view cell. Im using a 'flow' layout with 'vertical' scroll direction (as per IB).
First image is what I hope to achieve and the second is what I am able to achieve currently.
You need to implement custom UICollectionViewFlowLayout subclass for this - Creating Custom Layouts

UICollectionView that functions like a tableview

The designer came back with a layout that displays information differently.
Is it possible to make my UICollectionView function like a UITableView? Where each cell takes up one row and there is only one column?
Everything I found on the net seems to be about the opposite, making a UITableView be a UICollectionView
Actually, its very simple. Just make the width of the UICollectionViewCell equal to the width of the view.

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

UICollectionView within UITableView. How to tell tableview cell to change height when collection view gets taller?

I have a UITableView and one of my table cells is a UICollectionViewController subclass that contains a UICollectionView of displayed email addresses. When a user adds an email the UICollectionView and it’s cell in the table view should get taller.
I’m currently attempting to do this setting my collectionView height constraint to collectionView.contentSize.height in the LayoutSubviews method of my collection controller/cell class. My issue is that the cell in the UITableView is not changing size when this happens.
I am assuming that this is because there is nothing telling the table view that the height of the email entry cell has changed. I am currently using dynamic cell sizing - or trying to anyway. Even, if I call tableView.reloadData() this still does not work. I’m wondering if someone could give me a high-level idea of how they would set this up.
UPDATE:
I had a broken constraint issue that was part of my problem, but this is still not solved. While have proven that I can update the height constraint and that will update the size of the collection view, it's out of sync. It's always one update behind. Here's an image showing the 'UICollectionView' in green and you can see in the logs that I'm updating the constraint (yes, multiple times) each time after adding a new item to the collection, but it is not updating the bounds of the view instance. In this example, if I were to add a new item to the collection, the next time I inspect bounds.height it would be at 149.5. What am I missing!?
i had answered this question in another tableview inside tableview cell that will work for collection view too ,i explained it in this thread
ask me if you faced any problem
It seems you want to set the height of your table view cell dynamically. This detailed tutorial walks you through making a custom cell class that will have dynamic height. Unfortunately, this tutorial only walks you through how to do this with auto layout constraints and a storyboard. In the tutorial you'll notice that the height of the cell depends on the constraints put on a title label within the cell. Try doing the same thing, but applying the constraints on the content in your cell (the collection view cell).
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout

UICollectionView change layout - change cells

I have a UICollectionView which uses UICollectionViewDelegateFlowLayout. I've added a method which changes the layout when tapping a cell setCollectionViewLayout.
All the cells have a text label with text and I would like to empty all the text labels on every cell when changing the layout. What's the best way to accomplish that?
Thanks,
I would imagine the simplest way is just to call reloadData on your collection view at the same time that you change the layout (and have a conditional in your cellForItem data source method that empties the text labels upon each layout change).
Alternatively, you could have your UICollectionViewCells keep track of the layout they're currently displayed in, and adjust their views accordingly.

Resources