How to use auto-layout on a grid? - ios

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.

Related

Changing layout on rotation with multiple views moving

I'm working on an app where I've got a design with two similar layouts for horizontal/vertical. And it's on an iPad. I've found other answers but I can't use most of them because I've got two tableviews in my view, which means I can't use xibs. I'm also making it for the iPad so changing layout based on height/width variation doesn't work.
The design I'm trying to achieve is in the pictures below. What I'm having troubles with is moving the two views that are stacked on the right in landscape mode to be next to each other and short in vertial. Also I need to move those four buttons and the right-side table to being below the other two views.
I've tried overriding trait functions as described in this blog post but for the life of me can not get it to work.
I'm looking for any advice anyone could give me. I feel like I've hit a wall and can not figure out how I can implement this.
just give the height and width constraints of the subviews with respect to the superview in ratio it'll work.

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 :]

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.

UITableView with floating cells

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

Resources