Pages

September 14, 2013

Show or Hide all UIView subviews with a single function

While using Cocoa framework I often need to show or hide all child subviews of a parent UIView in a nutshell.
Use this Objective-C method in your Xcode projects!


/** Shows or hides all subviews of a View.

 @param hide Boolean value that defines hide (true) or show (false).
 @param ownerMainView A UIView or a subclass of UIView.
 @see showAllSubviewsOf:
 @see hideAllSubviewsOf:
 @see removeAllSubviewsOfClass:fromView:
 @see getAllSubviewsOfClass:fromView:

 */
+ (void)hide:(BOOL)hide allSubviewsOf:(UIView *)ownerMainView {
    if (!ownerMainView) { return; }
    for (NSInteger i=0; i<[ownerMainView.subviews count]; i++) {
        [[ownerMainView.subviews objectAtIndex:i] setHidden:hide];
    }
}



Download the ready-for-use source file (.m) of Show or Hide all UIView subviews with a single function

No comments:

Post a Comment