Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollview has ambiguous content width on Xcode 6

I can't understand how can I solve this auto layout problem, i have this View:

enter image description here

There is an UIScrollView with the elements you see in the View, but the View gives me this warning:

scrollview has ambiguous content width

I can't understand how to solve this problem, I want the the view is for the full screen size, and I want that the width will be the screen width, how I can solve it?

like image 329
Piero Avatar asked Oct 05 '14 16:10

Piero


4 Answers

I observed its fix in XCode 7.3 and it is just 10 sec work. I made a video on it. Check here:

https://www.youtube.com/watch?v=yETZKqdaPiI

All you have to do, add a subview to UIScrollView with same width and height. Then select ViewController and press Reset to suggested constraint. Please check video for clear understanding.

Thanks

like image 196
Vaibhav Saran Avatar answered Oct 17 '22 20:10

Vaibhav Saran


This is because you are not providing enough constraints so that Xcode can find Width of your scroll view. You can see on your screen there isn't any constraints that can be satisfied to find width of scroll view.

You can do it by providing leading and trailing space of Image view which contains fix width. It also can be done with any other views. But i will prefer control which contains fix Height & Width So there isn't require to set hugging priority or Compress resistance.

like image 24
dk-obl Avatar answered Oct 17 '22 20:10

dk-obl


Put everything in a View and that View put inside a ScrollView.

Editor -> Embed in -> View

like image 2
Borzh Avatar answered Oct 17 '22 22:10

Borzh


The solutions is:

  1. You have a UIImageView at the top. You set the width of the UIImageView to be the same as the width of the root view of the UIViewController

  2. You set the leading and trailing space of the UIImageView to the UIScrollView to be both 0

  3. You set the height of the UIImageView to be the height you want the image to be. And then you set the view mode of the UIImageView to be 'Aspect fit'.

like image 2
pumpum Avatar answered Oct 17 '22 21:10

pumpum