Prashanth Rajagopalan Prashanth Rajagopalan - 11 days ago 6
Objective-C Question

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.

Answer

Objective-C (KVC)

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

Swift:

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