UITableView with floating cells - ios

I am working on a specific type of list for an iOS app, where cells would simply have a specific width and height and then float left (think of something like CSS float:left), creating then a list that would scroll if more than 12 items (like the picture bellow).
I was thinking that perhaps this could be done by customizing UITableViewCell and setting the frame's width and height, so I could re-use the various benefits UITableViewController, delegate and dataSource offer. but unfortunately it seems that's not possible.
So, I'm now simply creating many UIViews and positioning them across its parent programatically.
I just would like to make sure this would be the right approach to achieve such kind of lists and if someone could let me know if it's indeed not possible to have this kind of functionality on UITableView and inherit all the goodness it offers.
Thanks guys

I know this question is already answered, but still...
I believe you can simply use UICollectionView since iOS 6.0.
Documentation
And this is how it looks like (image)
Maybe this will help somebody.

UITableView can only have cells that go in one direction. It's perfectly okay to create many UIViews (table view cells are also UIViews), if the number of them is reasonable. You can usually have a few hundred UIViews in a scrollview without seeing any performance issues, but that also depends on the complexity of what's inside the uiviews. Try it for yourself and if you find out, that you need too many uiviews, or that their complexity it too high, you can optimize further. You can set the .layer.shouldRasterize property to "cache" the content of the views. Or you can use CATiledLayer, which is something like a UITableView, but it supports tiles in all direction (and scrolling, zooming, ...).

Take a look at this project, I think may be helpful to for your problem
link

Related

UITableView height for dynamic cells

In my current project i'm trying to display data in a table View, however the former view does not take up the whole screen just a part of it. It's number of cells depends on an external json and the height of the cell is dynamic. Sadly there is no inbuilt way to use auto-layout(at least i think there's not) to expand the tableView depending on it's cells.
In the following picture there's an example of how one of these table views should look like:
And here's an example how the table view looks like using the autolayout:
Is there a way to expand the tableView to it's full size?
I've tried to follow various other questions but none have fully helped me, for exampled i've tried to this solution which sadly did not help me :[, creating a subclass of uitableview and overriding its intrinsicContentSize did not do the trick either.
Any help is much appreciated.
-Jorge :]

UICollectionView sticky supplementary view

Assuming I'm on a chat scenario, I want user images to move along with scroll until the other user's messages appear. Some visual example:
I'm using a subclass of UICollectionViewFlowLayout to display the messages and provide that initial left offset for the messages (the sectionInset property is not working on iOS 9 for some reason) and I assumed handling a custom supplementary view to do what's shown above should not be that hard, but apparently it is :)
Some info:
I'm not using standard header/footers for flowLayout since it add a space between sections that I don't want
Found this link which is pretty interesting from performance perspective but the example is somehow incomplete (great post though)
I'm trying to avoid shouldInvalidateLayoutForBoundsChange: to return true and recreate attributes every time since chat cells can be complex in terms of size calculation.
I believe this is not a weird scenario, have anyone accomplish something like this successfully? If so, I would appreciate some pointers.
Thank you in advance.
you can use sections for each cell groups. When using sections they have to be a clear background and be customized. So message cells can be scrolled below sections and circle images on section will be on top of its cells.
As a second way, you can use circle images apart from all collection items. For this, you have to create circle images that how many required. While scrolling up/down, they have to be moved as they will be anchored on top of message cells group.
I hope it helps for you :)

What's the best way to implement a vertical timeline - iOS

First of all, apologies if this question isn't meant here. I searched a lot but didn't find anything.
What is the best approach to create a vertical timeline kind of view?
I tried implementing via UITableView by alternating cells but that approach is very messy in terms of autolayouting (had to disbale autolayout and apply programtically when creating cell on alternate side), thereofre isn't working properly (getting stuck while scrolling). This is what I achieved:
I want to achieve something like this, which is also easily manageble:
Please Suggest. Thanks!
I would have 1 cell row with two image views. One on the left, one on the right. I think this would be easier to use auto layout.
Then you can hide the image view and labels that shouldn't be used.

How to enable scroll in UICollectionView?

I’m still learning to develop in iOS and Swift so I apologize beforehand if my question is too simple.
I have created an UICollectionViewController to show a matrix of elements. My issue is that the width of the screen is not wide enough to fit all the columns in a single row, so the excess of them are shown in another row below. Instead of this, I’d like to enable the horizontal scroll so the user can scroll to see all the columns in one single row.
I know UICollectionViewController already contains UIScrollView so I guess this should be as simple as to change a setting in the .storyboard but I couldn’t find it after many trial-errors :(
I guess it is related to the "Flow" layouts setting and that I need to handle a custom one, but don't know how exactly.
Would anyone be so kind to please help me? I haven’t attached any code because I’m using a pretty standard/out-of-the-box implementation of UICollectionViewController but if you want me to add anything, just let me know, please.
Many thanks in advance for any help!
I found the answer to my issue perfectly covered on this post:
https://www.credera.com/blog/mobile-applications-and-web/building-a-multi-directional-uicollectionview-in-swift/
It's definitely to do with your UICollectionViewLayout — that tells the collection view where everything should go. The collection view simply picks its scroll behaviour appropriately.
A UICollectionViewFlowLayout is a specific type of layout that fills one row column to the size of the enclosing view, then moves on to the next. So it does one-dimensional scrolling. Does that fit your use case?
If so then you should just be able to set the scroll direction on the flow layout.
If not then you'll need to write a custom subclass of UICollectionViewLayout that implements the layout behaviour you want.

How to use auto-layout on a grid?

Maybe I'm going about this the wrong way, but I have a grid like that below and have been futzing around with Auto-layout with only limited success. Currently the cells are individual UILabels that are embedded in UIViews. These views are inside a UIViewController. I've used auto-layout to center the views but this does not solve the problem laying out the labels. I've looked a bit at Container views, but it seems that every cell has to be the same size. Tables? It seems to me that I'd have the same problem in custom table view cell classes. I'm exploring this anyway.
The views look like this:
Can someone tell me a good way to solve this.

Resources