CristianMoisei
CristianMoisei

Reputation: 2279

Swift AutoLayout: UITextViews inside UIScrollView headache

I'm trying to wrap my head around how UIScrollViews work and while there are already some pretty good answers, they don't seem to cover UITextViews, so I was wondering if anyone could tell me more about what UITextViews require to work in a UIScrollView. My setup looks like the image below and I'm getting errors that the ScrollView has no height or width constraints.

If you could, I'd appreciate it if you could elaborate a little on why this doesn't work and what requirements TextViews have when placed inside ScrollViews.

enter image description here enter image description here enter image description here

Upvotes: 1

Views: 43

Answers (1)

Andrew
Andrew

Reputation: 471

So https://www.dropbox.com/s/gujry7ngziaipm7/Main.storyboard?dl=0 here is the fixed variant. I found a few errors:

  1. Top constraint from Title Input was to view from another hierarchy

  2. Content View - your root view in UIScrollView was without x, y constraints, so I added trailing, bottom, top and leading constraint.

And maybe some tips:

  • Your constraint should be relative to each other, so you have no need to offset all views from Safe Layout.

  • Try to separate your viewControllers to different Storyboard files, otherwise if you would work in team, it would be a real headache to fix merge problems in git)

Hope it will helps you in your project)

Upvotes: 1

Related Questions