mrGott mrGott - 1 year ago 80
Swift Question

Long/High View with ScrollView in Xcode 7 for iOS

First of all, sorry for the title, not sure what's the right name.

I'd like to create a long View in Xcode for a project (i'm doing it in storyboard). I'm using Swift (not Obj-C).

I'd like to display an imageView, some flexible (in height) labels, some buttons that in fact are longer then the ViewController in Xcode's storyboard.

I couldn't find any resource on how to achieve it. Somewhere I read that it's done by code, maybe I should do XIB? I'm pretty new to iOS development and I'm stuck.

What I'm trying to achieve is smth like this (image below, it's just a template from google search) but I'd like to have large image and lots of stuff beneath it:

enter image description here

How should I do it? Using swift? Some examples or resources will be very helpful.


Just in case you found this question and you are also willing to find out how to do it I will tell you the best (but not easiest) way to build view like on the screenshot is Programatically. Yeah, the answer says Tableview, some might say XIB but after a long search I came up with the result that the best way is doing everything Programatically. If you do search for creating view controllers programmatically there are actually lots of great resources and most of developers advice you to do it programmatically as it gives you more control and flexibility.

Answer Source

I guess the UITableView will be a better approach thenUIScrollView

If your content is going to be static or constant in number of views then simply use a UITableView with static cells. If your content will be dynamic i.e. dynamic number of rows depending on lets say JSON API response then dynamic cells with some coding in your ViewController

It will also help your requirement of dynamic heights of views e.g. labels since iOS 8+ supports UITableViewAutomaticDimension which can layout UIViews depending upon content automatically for you.