3

I am looking to display information (a 2-digit int) on an iOS app in a 4x4 grid design with a small label underneath each bit of data (the int's).

If I was to do this in Excel it would look like a 4x8 Grid (including text).

The data will all be pulled from an SQL database (different cells = different queries)

I have been trying to lay this out using 32 different 'labels' but getting the constraints correct is proving impossible.

Is there a different method I should be using in doing this? A table view, or stack view, or something completely different?

jscs
  • 62,161
  • 12
  • 145
  • 186
RDowns
  • 580
  • 1
  • 7
  • 25
  • You can check the UICollectionView, that might be the answer you are looking for. Collection view is meant for grid kind of things – Janmenjaya Oct 14 '16 at 10:23
  • Thanks, does a Collection View object have to be inside a Collection View Controller? - as currently I already have a View Controller set up with a Scroll View inside of it – RDowns Oct 14 '16 at 10:28
  • you can make your view controller a collectionview by making it conform to the UICollectionView delegates. take a look at the answer code [here](http://stackoverflow.com/questions/31735228/how-to-make-a-simple-collection-view-with-swift) – Danoram Oct 14 '16 at 10:32
  • Yes collection view is written over scrollView, so like tableView, so collection view is having default scrolling, based on the content – Janmenjaya Oct 14 '16 at 10:40
  • Thanks Danoram, in looking at the example provided i think because of my data labels they might not 'fit' so stack views may be the way forward... i'll try those first. Thanks for responding :) – RDowns Oct 14 '16 at 10:43

2 Answers2

0

If you know you will only have a 4x4 design, you use stack views. You can embed the stackviews in each others.

You would create a first horizontal stack view. In this stack view, you add two stack views for the columns etc.

Kamchatka
  • 3,488
  • 4
  • 34
  • 63
  • or 4 vertical stacks for my case in particular? – RDowns Oct 14 '16 at 10:44
  • 4 vertical stacks containing a digit + label underneath. But you need to arrange them in a grid of 4x4, and you will achieve it by using stack views. – Kamchatka Oct 14 '16 at 10:48
0

If the grid is fixed, never scrolls, and never changes sizes then I agree with @Kamchatka, use nested stack views. (Say for example each row is a horizontal stack view and then you put those row stack views in a vertical stack view.)

If you need to be able to handle varying numbers of cells, or scrolling, then you should look at using a UICollectionView.

Duncan C
  • 115,063
  • 19
  • 151
  • 241