Question

Whenever I want to use scroll view , I take UIView in IB & add my contents (label , text field , imageviews etc) on that UIView. Once done , I add UIView as subview to scroll view & set scroll views content size in programatically.

Whether I add constraints or not to UIView & its subviews , it works perfectly.

So my question is do we need constraints for UIView & its subview that added in UIScrollView ? Can anybody explain this ? Thanks in advance.

Was it helpful?

Solution

Yes, You Can add constraints to all subviews in the scrollview.

If you add constraints to all subviews,

  1. you don't need to set the content size and content size will be automatically calculated in runtime based on your constraints.
  2. you don't need to set frames to views.
  3. No worry about orientation support.
  4. No worry about 3.5/4 inch iPhones.

So better to use Auto Layout to views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top