1
votes

I am making a form based UIScrollView, which will contain some labels and text fields.

My ScrollView Height will increase as per the iOS device height.

PS: I do not want to add constraint to each and every element of the Scrollview, because in my case there could be 100 form fields.

iphone 4 inch

iphone 3.5 inch

What I want is, the inner content to fully occupy my scrollView like this:

Requirement

Till now there a are no special constraints, the button is tagged with the bottom edge and the scroll view is pinned from the top edge. Also, the vertical spacing between scrollview and button is defined.

This is the autolayout constraint screenshot.

enter image description here

2

2 Answers

0
votes

If the number of labels is variable, I recommend doing them in code, rather than in Interface Builder.

In code, you can use a loop to set every label to have the same width/height as the one above it. You may want to set their height to be >= a minimum value. Be sure to anchor the first label with the top, and the last label with the bottom.

But this can be cumbersome, why not just use a UITableView? you may modify the row height to let the cell fully occupy the view.

- tableView:heightForRowAtIndexPath: - tableView:estimatedHeightForRowAtIndexPath:

-1
votes

I just face the same issue and already write a pod called TLFormView that do exactly that: a form based on UIScrollView.

It also has some nice features like:

  • declarative form taxonomy with TLFormModel Just extend it, add the properties you want and that's it. No delegate, no event handling, no boilerplate.
  • a nice way to handle different layouts for iPhone and iPad
  • conditional visibility with an NSPredicate that can access all the values in the other fields (e.g: show field A when field B has certain value)
  • in place help with a popover
  • all the fields are TLFormFields that extend UIView so you can place whatever you need.

You can try it right from the command line with pod try TLFormView. If you want to know more I wrote some blog post about it here.

Please let me know your thoughts about it here or as a comment in the blog posts. Also any contribution is extremely welcome in the GitHub repo