4

enter image description here

As you can see, I have a UIView(red color) that has constraints - leading, bottom, width and height. All set to default(1000) priorities except height(999). Inside this UIView are three UIButtons those have constraints - leading, top, width and height. All set to default(1000) priorities except height (2). So that superview's height can override the innerviews height. At the click of orange button. I set UIView's height constant to 0.

And the result is this - in pic below. At bottom you can see content(text) is not compressed to hide itself. What should I do. I have played with vertical compression resistance. Please don't say set buttons to hidden etc.

enter image description here

  • 2
    How are you setting the height constraints of inner views? Are they having constant height constraint? If yes then try by providing the constraint as in a multiplicative factor of super view, that way when super view's height is 0, their height will also be 0. Also top constraint should be felxible like `>=0 , <=c` instead of non-zero value. – Gandalf Oct 30 '15 at 10:58
  • 9
    Would setting clipsToBounds=YES on the superview work? It seems like this is what you want – Alex Oct 30 '15 at 12:26
  • +1 for @Alex's comment. UIViews by default do not clip subviews, so even if your view's bounds were CGRectZero, you could still see its subviews. (Opinion time: I never really understood why Apple chose to make this the default behavior. Seems very counterintuitive.) – n00neimp0rtant Oct 30 '15 at 14:44
  • Both Gandalf's & Alex's comment are helpfull – Bharat Modi Apr 21 '16 at 04:51

1 Answers1

0

// Orange Button Action Clicked

@IBAction func orangeAction(_ sender: Any)
{

redViewHeight.constant = 0

redView.clipsToBounds = true

}

// ClipTo bound : the subview that fits within the bounds of the superview.

Nikunj
  • 280
  • 3
  • 15