Last active
August 29, 2015 14:14
-
-
Save csknns/4a339fcd0839d9f4afbb to your computer and use it in GitHub Desktop.
Print the subview hierarchy of a UIView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+PrintSubviewHierarchy.h | |
// | |
// | |
// Created by Christos Koninis on 2/2/15. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIView (PrintSubviewHierarchy) | |
- (void)printSubviewsWithIndentationLevel:(int)indentLevel; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+PrintSubviewHierarchy.m | |
// | |
// | |
// Created by Christos Koninis on 2/2/15. | |
// | |
#import "UIView+PrintSubviewHierarchy.h" | |
@implementation UIView (PrintSubviewHierarchy) | |
- (void)printSubviewsWithIndentationLevel:(int)indentLevel { | |
NSArray *subviews = [self subviews]; | |
for (UIView *currentSubview in [self subviews]) { | |
NSMutableString *currentViewDescription = [[NSMutableString alloc] init]; | |
// Indent the actual description to provide visual clue of how deeply is the current view nested | |
for (int j = 0; j <= indentLevel; j++) { | |
[currentViewDescription appendString:@"\t"]; | |
} | |
[currentViewDescription appendFormat:@"[%lu]: class: '%@'", | |
(unsigned long)[subviews indexOfObject:currentSubview], | |
NSStringFromClass([currentSubview class])]; | |
NSLog(@"%@", currentViewDescription); | |
[currentSubview printSubviewsWithIndentationLevel:indentLevel+1]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment