0
votes

I have searched the post before I submit this question.
How to optimize screen size designed for 4 inch compatible with 3.5 inch

But above post does not answer my question.

Our designer send us 4 inch design UI, I use xib with autolayout to implement the design. And we're informed by the manager that we need to support 3.5 inch screen...

We do not want to creat another one xib to adapt the 3.5 inch screen, all we want to do is to add UIScrollView for the xib, is there anyboby have any idea to implement by this way and do not need to modify our exist xib layout constraints?

2
Why are you not using the Storyboard for it ? that would be easy to manage .Aashish1aug
@Aashish1aug thanks for you answer, but this project we already use xib not storyboard, is there any advise for xib?Mellong Lau
@Mrunal , we have used auto layout, but our design is for 4 inch, it means that the screen height is much more higher than the 3.5 inch, so we need to add scroll view to make it scrollable.Mellong Lau
Okay, Have you try to change the setting for Freefrom in Attribute inspector of your xib. As you are using Autolayout, I think it will be work with little bit correction.Aashish1aug

2 Answers

1
votes

Try this way around.

  • Select all your view objects from your xib or storyboard scene
  • In Xcode menu > Editor > Embed In > View
  • Select again the newly added View (referring it as ContainerView)
  • Add the ContainerView into a ScrollView using Xcode menu > Editor > Embed In > Scroll View
  • Now adjust all your constraints for your inner most view objects related to ContainerView
  • Keep the ContainerView height normal even if it goes beyond screen height
  • Adjust top level ScrollView height connected with screen bounds.
  • In codebase, set the ScrollView ContentSize = ContainerView.frame.size

Reference:

enter image description here

So your view hierarchy would look like this:

Default Controller View (UIView)
    |- Scroll View (UIScrollView)
        |- Container View (UIView)
            |- Other ViewObjects like UILabel,
            |- UIButton,
            |- UIImageView, etc.

Hope this helps.

0
votes

Just add scroll view as parent view and check that all constraints is correct and system can calculate content size.