0

Possible a duplicate, but I tried could not make it work so came here. I (new to autolayout) have two UILabel place one below each other with fixed height space.Both can increase with as per text with in it.

enter image description here

When First UILabel hides bottom should move to First place. How to do it using constraints in view only? I know how to do by creating IBOutlet connection of constraints for second UILabel. EDIT: Given question is about more about content hugging related, where as my question is add constrains to move to first UILabel position when first hides.

Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75
  • whenever label hides its frame is there....means that label's frame is not removed....so just try to set frame height to 0 meanwhile label is hidden – Bhavin Bhadani Aug 06 '15 at 06:06
  • Thanks for reply, but wanted to use constraints only. I have idea with other way work around. – Sanoj Kashyap Aug 06 '15 at 06:09
  • possible duplicate of [UILabel sizeToFit doesn't work with autolayout ios6](http://stackoverflow.com/questions/16009405/uilabel-sizetofit-doesnt-work-with-autolayout-ios6) – Grzegorz Krukowski Aug 06 '15 at 07:01
  • You need to work with ContentHuggingPriority and set the UILabels related to each other. Check the duplicated thread I marked this as duplicate: http://stackoverflow.com/questions/16009405/uilabel-sizetofit-doesnt-work-with-autolayout-ios6 – Grzegorz Krukowski Aug 06 '15 at 07:02
  • my question not about the setting hugging priority, where as it is about what constraints should I put to move second label to first label position when first label hides. – Sanoj Kashyap Aug 06 '15 at 08:00

1 Answers1

1

The only way to achieve what you want with AutoLayout is to set constant of all related constraints to zero. And remember NEVER try to set frame or bounds of your view if you are using AutoLayout(unless you override layoutSubviews and do the stuff in that method, which you rarely need to).

You can check out this tiny project: https://github.com/neevek/UIView-Visibility, I bet that is what you want :-)

enter image description here

neevek
  • 11,760
  • 8
  • 55
  • 73