I want a collectionview cell should be the dynamic height. I am getting data from server and loading in to tableview inside collectionview cell. That cell height should be change according to the table cell height, I am getting till here. But the problem is The cells are not aligning from the top. see this pic. The cell should create from top. This is demo code. Thanks
If I'm understanding your problem correctly, try setting self.yourCollectionView.automaticallyAdjustsScrollViewInsets = false
You will need to extend UICollectionViewLayout. And then in the prepareLayout method, you will need to specify the calculated frames of every item of your collectionview.
There are two tutorials:
http://www.skeuo.com/uicollectionview-custom-layout-tutorial is a very good tutorial for custom layout.
https://github.com/betzerra/MosaicLayout and https://www.cocoacontrols.com/controls/rfquiltlayout is pretty much what you want. A related question about rfquiltlayout on stackoverflow is RFQuiltLayout and UICollectionView
Related
I'm setting up a new prototype for a project, and I need to use a UICollectionView. The thing is, I'm struggling trying to set the correct margins to my UICollectionViewCell, but it doesn't work the way I want.
Here is my problem. I have a UICollectionView showing 3 cells. I'm showing only one cell in every "page". The orientation is horizontal and I'm using pagination as well.
The problem is the last cell. What I need to do to show the right margin of the last (third) cell.
Here's the image. The first one and second one are fine. The third is has a problem.
I'm subclassing the UICollectionViewCell. I don't thing that's the problem, though.
Here's the UICollectionView configuration and settings.
The UICollectionView is a 280x280 square. And the UICollecitonViewCell is a 260x260 square.
Here's the UICollectionViewCell configuration.
No extra code to change UICollectionView or UICollectionViewCell dimensions. I', trying to do the whole thing using Storyboard.
Any advice?
Thank!
Well.. After testing again, and again, and again I realised how UICollectionView and UICollectionViewCell work.
In my above set up, I make 2 big mistakes.
1) In the UICollectionViewCell setup, I set Custom size. I changed to default instead.
2) In the "Section Insets", I changed the right value to 10.
Here's the final result.
:)
I had created two type of cells for my CollectionView, both are of different heights.
But when I run the app, the black cell is cut in half. I am unable to understand why. I tried changing the size of the cell, but it in turn makes the black cell over lap the cell below it. Please help with this.
Thanks
The size of the CollectionView item has to be changed dynamically. Kindly follow the following link to solve
UICollectionView - dynamic cell height?
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.
I'm trying to make self resizing cells for my collection view. Ill display text parts and those text parts have many sizes, since every cell will have a paragraph. Reading a guide on appcoda and useyourloaf i got the solution to make it with table view, so the only thing i can't do on the collection view cell is this
self.tableView.estimatedRowHeight
for obvious reasons I can't use it on collection view. Is there any similar thing that I can do for collectionView cells?
PS: I can't change the collection for a tableView.
PS2: I'm using swift
In theory there is; Apple has been claiming since WWDC 2014 that there are self-sizing collection view cells in exactly the same way as for self-sizing table view cells.
But in fact every time I try this feature, my app crashes. So in my view the answer is: no, if you want dynamically sized collection view cells you will have to size them dynamically yourself. This is not difficult, however. Just implement collectionView:layout:sizeForItemAtIndexPath: and set the size of the item. If you want it to be based on internal constraints, call systemLayoutSizeFittingSize: here.
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