Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Tuesday, June 7, 2016

Swift - Why ScrollView not full screen?

Swift - Why ScrollView not full screen?


I had inserted a ScrollView into UIViewController and dragged ScrollView to fill the space between the navigation bar and the RAM label below:

enter image description here

But when I run the app, the ScrollView does not fill the space:

enter image description here

Please help me! Thank you very much.

P/S: Sorry for my english is bad.

Answer by Vibha Singh for Swift - Why ScrollView not full screen?


Uncheck Adjust subview option and add

scrollview.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

enter image description here

Answer by Sushree Swagatika for Swift - Why ScrollView not full screen?


You need to add constraints for your scrollView. Set the leading and trailing constraints to 0. Pin the height of your scrollView and also don't forget to set the top layout constraint. You can either pin the height or add bottom layout constraint to your page control.

Constraints are very important and its even more important to set it correctly. Check the Apple Documentation - Working with constraints in IB

Answer by Sweeper for Swift - Why ScrollView not full screen?


The scroll view is not covering up the whole thing because you are running the app on a much bigger phone. The simplest solution is to run the app on iPhone 5.

However, if you want to solve the problem on all sizes of iOS device, you need to add constraints.

Constraints are things that tells a view when and how much it should resize and where it should be positioned.

To add a constraint, just select the view you wish to add a constraint to and go to the bottom right corner. You will see 4 buttons:

  • The leftmost button is used to embedding views in stack views. This is a feature of iOS 9. If your deployment target is lower, just ignore it.
  • The second button to the left is for adding constraints related to alignment - where the edges of the views are, what its baseline is and where it is positioned in the X and Y axes:

enter image description here

  • The third button to the left is used to add constraint related to margins, width, height and how the width and height should change when it is asked to resize (keep the aspect ratio, for example):

enter image description here

  • The rightmost button is used to let Xcode decide what constraints you should add. And I think most of the times its choices are okay. Sometimes though, you still need to do some tweaking before it works.

"So... what constraints should I add?" you asked.

Well, I think I should teach you how to think when you want to add a constraint. This way, you can figure it out yourself in the future.

You should first let Xcode guess what constraints you want. Just click the rightmost button and click "Reset to Suggested Constraints". This can save a lot of work if Xcode can get it right. So remember to always do this first.

Then, run your app on various devices and see if the view's position, size, and alignment are as you expected. If it is not, you might have to add and/or remove some constraints.

For example, if you found that your view is always the same size on different devices, (that could be bad because it means that some content my go out of view on smaller devices) it's probably because Xcode added a width and/or height constraint to the view. You should delete that so that the view's width and/or height is not fixed.

You can find your view's constraints in the view hierarchy:

enter image description here

Just select the constraint and press delete.

Answer by Alex Zansir for Swift - Why ScrollView not full screen?


Uncheck constrain to margins and add 0 every one of the four limits of spacing to nearest neighbour.

Answer by vrwim for Swift - Why ScrollView not full screen?


My guess (from the little information we have) is that you are creating a constraint from your scrollview to the top of your view with a value equal to the height of the navigation bar. Set the value of this constraint to 0.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.