0

I am new in iOS development and Swift, I'm struggling creating a relatively simple detail page.
For now I have this layout made with interface builder: enter image description here

The parts highlighted in red must have variable heights, every element is inside one big stack view which is inside a big scroll view.

The list of phone numbers is a label with Lines set at 0 so if I understood correctly that element will size itself correctly with the content.

I don't know how to implement the other two lists and how to make the whole layout to wrap onto the content.

To make you understand better I'm struggling because I'm used to make layouts in android and so making extensive use of the wrap_content option.



Thanks in advance

Larme
  • 24,190
  • 6
  • 51
  • 81

1 Answers1

0

I think, you could use UITableView for image+text list and UICollectionView for images. If you are using constraints you have to add height constraints to your tableView and collectionView, but you could update those constraints from code with real heights.

Sunny
  • 137
  • 7
  • I feared I had to update the constraints by hand, con you give me an example of filling the UIListView while updating the height constraint? Also I don't know how to update the height constraint of the UICollectionView because I don't know how many icons will take to reach the second row. – Lorenzo Lodi Jul 06 '16 at 16:11
  • UITableView has several delegate methods, and you should implement some of them to fill your table view. For example your `tableView:cellForRowAtIndexPath` method should return your custom cell, and your `tableView:heightForRowAtIndexPath` method should return your cell height. As I see from your image, all cells have the same height. Also you should create an outlet to your tableView height constraint and update this constraint every time you update table view data. You could calculate table view height as cellsCount * cellHeight. – Sunny Jul 06 '16 at 16:21
  • I am really struggling with autolayout here, nested stack views are driving me crazy with constraints and behavior, is there a simpler method to obtain this result? I'm willing to do the layout from scratch – Lorenzo Lodi Jul 07 '16 at 09:57
  • You don't have to use nested stack view. Just use constraints. But if you want your tableView fit content, you need some additional actions, it is not as simple, as android's wrap content. You may find [this link](http://stackoverflow.com/questions/2595118/resizing-uitableview-to-fit-content) useful. – Sunny Jul 07 '16 at 14:37