Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide UIView subviews

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.

like image 733
Prashanth Rajagopalan Avatar asked Oct 17 '13 18:10

Prashanth Rajagopalan


People also ask

How do you hide a view in Objective C?

hidden = YES; // or view. hidden = NO; or by calling setHidden: [view setHidden:YES]; // or [view setHidden:NO];

How do I hide a view in Swift?

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.

What is a hidden view?

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.

What does ishidden do?

A Boolean value that determines whether the view is hidden.


1 Answers

Objective-C (KVC)

[mainView.subviews setValue:@YES forKeyPath:@"hidden"];

Swift:

mainView.subviews.forEach { $0.isHidden = true }
like image 123
rfrittelli Avatar answered Oct 16 '22 22:10

rfrittelli