0

This how my view looks like:

enter image description here

I want label 2 to have a fixed 8pts horizontal spacing with label 1 but also having its bottom equal to the image view on the left. Then while having those fixed constraints, the height of label 1 and label 2 may vary as long they maintain close to each other(8 pts of horizontal spacing) and label 2's bottom may be equal or less that the bottom of the image view.

This is what I tried, but it seems like there is a conflict with the constraints:

enter image description here

JLT
  • 3,052
  • 9
  • 39
  • 86
  • Need more explanation of your fixed and varying constraints for both the labels. – Annie Gupta Dec 11 '16 at 06:53
  • @SharpkitsInnovations Hi, I just want Label 1's top to be aligned to the top of image view, Label 2 to align with the bottom of imageView, Label 1 and 2 have horizontal constraints of 8 while both of them can vary in heights. – JLT Dec 11 '16 at 07:11
  • height of image will be static? – Bista Dec 11 '16 at 08:50
  • @Mr.Bista No, height of image will also vary. – JLT Dec 12 '16 at 01:39

2 Answers2

1

The error is because Xcode is confused about which label should compress when there is more content in them and hence show the constraint conflict.

Just increase the Vertical Compression Resistance of your Label 1 greater than that of Label 2.

This will resolve your issue.

If you need detailed explanation on this just visit this link: Cocoa Autolayout: content hugging vs content compression resistance priority

Community
  • 1
  • 1
Aakash
  • 2,239
  • 15
  • 23
0

What I got from your question is you want maximum height of your Label1 Plus Label2 should not exceed from imageview's height (still varying the labels height till possible).

Add constraints of your Label1 as:Leading space to imageview, Align top to Imageview, Right space to superview: Greater than or Equal to superview, (don't give fix height to any labels) For Label2, Leading space to imageview, Align top to Label1, Right space to superview: Greater than or Equal to superview,

Now, give bottom space to the Label2 Greater than or Equal to the imageview's bottom.

Note: You need to give vertical content hugging content hugging priority of Label1 to greater than Label2 (or vice-versa according to your requirement).

Like

Sunil Chauhan
  • 2,074
  • 1
  • 15
  • 33