Reputation: 2016
I want to hide a non child UIView
in a UIView
but I don't know how to do it.
To be specific, I have a UITableView
. Each UITableViewCell
has another view inside it (a wrapper view called wrapperView
). 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 contentView
.
How can this be solved? Is there a way for a UIView
to clip other views on the same level(not parents nor children)? Or "transfer" the labels to the wrapper view?
Upvotes: 1
Views: 51
Reputation: 131491
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.
Upvotes: 2