Piero
Piero

Reputation: 9273

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?

Upvotes: 8

Views: 11774

Answers (6)

Bug Hunter Zoro
Bug Hunter Zoro

Reputation: 1915

I too faced this issue and the only way i got it solved was using the below strategy

  1. Add a scroll view and set its constraint to fill in the screen
  2. Add a UIview inside the scroll view lets call this view as the content view. In this contentView, set top, bottom, left and right margins to 0 (of course from the scrollView which is the superView);

This should do it now you can follow step 3 and continue with your UI

  1. Place your view inside the content view and add constraints to it accordingly.

Hope it helps

Upvotes: 0

Vaibhav Saran
Vaibhav Saran

Reputation: 12908

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

Upvotes: 3

pumpum
pumpum

Reputation: 645

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'.

Upvotes: 2

Gabriel Tomitsuka
Gabriel Tomitsuka

Reputation: 1141

I had the same problem a month ago. Add a constraint that makes the UIView inside the UIScrollView have the same size of the UIScrollView's content width. If you have multiple views inside the UIScrollView, put your UIViews inside a new UIView and make sure the new UIView has the same content width size as the UIScrollView.

Best regards,

Upvotes: 0

Borzh
Borzh

Reputation: 5195

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

Editor -> Embed in -> View

Upvotes: 2

dk-obl
dk-obl

Reputation: 761

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.

Upvotes: 2

Related Questions