I have UIView which have n number of subviews. Let say n as 600 subviews. I know there is a way to hide all the subviews by the following code
for (UIView *subView in mainView.subviews) {
subView.hidden = YES;
}
But is there are any other proper way or API's to hide all the subviews.Thanks in advance.
hidden = YES; // or view. hidden = NO; or by calling setHidden: [view setHidden:YES]; // or [view setHidden:NO];
If you need to reserve space in a layout based on the measurement of a view, but never want to show that view, you can use the hidden() modifier.
A hidden view disappears from its window and does not receive input events. It remains in its superview's list of subviews, however, and participates in autoresizing as usual. Hiding a view with subviews has the effect of hiding those subviews and any view descendants they might have.
A Boolean value that determines whether the view is hidden.
Objective-C (KVC)
[mainView.subviews setValue:@YES forKeyPath:@"hidden"];
Swift:
mainView.subviews.forEach { $0.isHidden = true }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With