Lawrence413 Lawrence413 - 1 year ago 98
iOS Question

Hide non child UIView in UIView

I want to hide a non child

in a
but I don't know how to do it.

To be specific, I have a
. Each
has another view inside it (a wrapper view called
). The wrapper has some labels set up in IB and some created programmatically. I have created a custom slide mechanism that reveals buttons under the wrapper (like the standard one does).

The labels created programmatically don't exceed wrapper's bounds because it clips the subviews. The problem is with the labels created in IB. They are the subviews of

How can this be solved? Is there a way for a
to clip other views on the same level(not parents nor children)? Or "transfer" the labels to the wrapper view?

Answer Source

It isn't completely clear what you're asking. A view will only clip it's subviews, not views that happen to fall within their frame rectangle but aren't subviews.

If you want to move a view object from one view hierarchy to another you can use addSubview(_:) to do so. That will automatically remove it from it's current parent view. To quote the Apple docs:

Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download