Scroll View and Tableview programmatically alignment

329 Views Asked by At

I am implementing a UIScrollView which holds some user data. I am downloading additional data from my server. Once downloaded the contentSize of my UIScrollView should be the original size + the number of cells times their height.

All the UIViews are aligned and set programmatically.

The UITableView is the lowest and is supposed to always stretch to the bottom of the screen.

In my viewDidLayoutSubviews I set the following

    groupsCountLbl.frame = CGRectMake(groupsLbl.frame.maxX + 5,
    seperatorLbl.frame.maxY + 15 , 40, 20)
    groupsCountLbl.sizeToFit()

    table.frame = CGRectMake(0, groupsCountLbl.frame.maxY + 10,
    bounds.width, bounds.height - groupsCountLbl.frame.maxY + 10)

    scrollView.contentSize = CGSizeMake(bounds.width, bounds.height
     + self.table.frame.height)
    scrollView.scrollEnabled = true

Rather than filling the whole view it appears like this: enter image description here

1

There are 1 best solutions below

4
Marco Santarossa On

Try setting your UIScrollView bounds to superview

NSLayoutConstraint.constraintsWithVisualFormat(
  "V:|-[scrollview]-|",
  options: [],
  metrics: nil,
  views: ["scrollview": scrollview])

NSLayoutConstraint.constraintsWithVisualFormat(
  "H:|-[scrollview]-|",
  options: [],
  metrics: nil,
  views: ["scrollview": scrollview])

Let me know in the comment if you have some problems