Hide UIView subviews

Prashanth Rajagopalan picture Prashanth Rajagopalan · Oct 17, 2013 · Viewed 14.1k times · Source

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.

Answer

rfrittelli picture rfrittelli · Oct 17, 2013

Objective-C (KVC)

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

Swift:

mainView.subviews.forEach { $0.isHidden = true }