3

I have one UIView, it's having few subview controls like label's and textbox. it is also having one switch control.

I want to hide/display (like collapsible) the portion on the superview based on the switch change. However when I try to do it with constant of superview, it just changes the superview height but all subview does not getting hides.

could you please help me to figure out this.

Thanks,

Parth Pandya
  • 1,460
  • 3
  • 18
  • 34

2 Answers2

15

Set UIView's property clipsToBounds = true. This prevents the subviews from being drawn when their frame lies outside the bounds of the superview

e.g.

superView.clipsToBounds = true

Note that for layers you can use:

superView.layer.masksToBounds = true
Lneuner
  • 1,090
  • 1
  • 9
  • 19
-1

There are a number of methods of UIView that allow you to modify the view hierarchy.

bringSubviewToFront:
sendSubviewToBack:
insertSubview:atIndex:
insertSubview:aboveSubview:
insertSubview:belowSubview:
exchangeSubviewAtIndex:withSubviewAtIndex:

You can use any of this as per your requirement.

Piyush
  • 1,534
  • 12
  • 32