2

I am trying to satisfying the constraint form a long time but getting above error i.e. is "Need constraints for y position or height" for Yellow View and Green View. Basically I have 2 UILabel (dynamic height) within UIView and UIImageView of 4:3 ratio within a Cell.

enter image description here

And my applied constraint is

enter image description here

I am also including sample project here with above issue.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gaurav Pandey
  • 1,953
  • 3
  • 23
  • 37

2 Answers2

1

Just one Constraints required

enter image description here

Provide SubHeading label height >= (Greater than equal to ) Constraints

Because of you have applied aspect ratio of UIImageView of 4:3 so it required to fixed other items height and Y position before it apply a ratio to it. By giving height to subheading Autolayout is able to calculate approx value min required in image ratio

Hope it is helpful to you

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
0

I am attaching two images, one is output and another one is the constraints of views (UILabel, UIImageView). For testing purpose, I put long texts in UILabel, after testing I reduced the text to 'Heading it is' and 'Sub heading it is'. Let me know, if its working of not.enter image description here

enter image description here

enter image description here

sRoy
  • 267
  • 2
  • 5
  • thanks for your time. Above thing is also working for me, but I put above thing in a View or UITableviewcell, they height is not automatically calculated. – Gaurav Pandey Dec 06 '17 at 11:49
  • If you follow the procedure which I shared, the height will be automatically calculated. No matter ‘Heading:’ is there or not. – sRoy Dec 06 '17 at 12:51
  • Have u applied the ratio also in imageView (for ex. take 4:3) – Gaurav Pandey Dec 06 '17 at 13:28
  • If your image is of 4:3 then, setting the image as Espect fit will do the work. And top, bottom, leading, trailing all will be + 5. Thats all. – sRoy Dec 06 '17 at 13:50