Ambiguous Layout - "Height is ambiguous for 'Image View'"

26,356

Solution 1

The layout for the image view height property is ambiguous. When you use autolayout, it doesn't use the height of the image view in Interface Builder. Instead it uses the constraints set on the image view.

Create a height constraint on the image view and set it to what you want the height to be (in the case of a fixed height). If you want the height to scale, create constraints for the top and bottom of the image view to the image view's super view. For the screenshot you provided, you may want to set a constraint from the top of the image view to the top layout guide.

Solution 2

enter image description here

set intrinsic size as Placeholder.

Share:
26,356

Related videos on Youtube

user
Author by

user

✨ I love you 😘

Updated on October 16, 2020

Comments

  • user
    user over 3 years

    iOS7 has really been jerking me around.

    This is a project imported from iOS6 that ran smoothly on all devices I tested on. Somehow the image view pictured gets set to something like 312x400 at runtime, ignoring the specification for height that I set in the storyboard.

    I'm aware I'm missing some detail about autolayout but what gives? Why does the height I provided not matter at all, and why is this any different from Xcode4.x/ios6?

    Snapshot from Xcode5

  • user
    user over 10 years
    So why is there even the dummy box that lets me specify a height? And can I not simply generate constraints from placing the item where appropriate in IB and setting a fixed size?
  • Andrew
    Andrew over 10 years
    Those fields exist in IB so it knows what size to display the view inside IB only (if autolayout is enabled). If autolayout is disabled and the old struts and springs system is enabled, the fields are used for width and height at runtime. With autolayout enabled you must create constraints if you want a fixed size.
  • Doug Voss
    Doug Voss almost 8 years
    Thank you! This allowed my UIControl subclass to size to fit the label text size that was in it in an easy way without having to mess with explicitly setting width constraints and got rid of the warning.
  • Mansuu....
    Mansuu.... over 6 years
    I am also facing a similar issue in UICollectionView.I am using auto layout to set data in UICollectionViewCell. Every thing looks perfect in interface builder. After running app I debug my app and it shows ambiguous position for UIView.