David David - 1 year ago 168
iOS Question

Xcode; Set height of UIScrollView automatically depending in its content

I'm developing an iOS app with Xcode and Swift.

In one

there's a
. In this
there are multiple
. But it takes more height that it's fitting on the device screen and I'm not able to scroll down to see the remaining content.

Does anybody know a way to set
height automatically depending in its content?

P.S. Of cause, I already googled, but the codes I found don't work.

Answer Source

Decleare outlet like and connect:

@IBOutlet var scrollView: UIScrollView?

Set its content size using contentSize method like this:

self.scrollView!.contentSize = CGSize(width:1234, height: 5678)

Set Y position of last UI content plus its height too to the height: 5678 parameter. So you will be able to see all contents.

set your constraints accordingly see image. enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download