Last active
December 23, 2015 06:05
-
-
Save ourui/6b8c7760851c69b8f80b to your computer and use it in GitHub Desktop.
Recursively Print UIView Hierarchy
This file contains hidden or 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
//po [[UIWindow keyWindow] recursiveDescription] //private api | |
// Recursively travel down the view tree, increasing the indentation level for children | |
- (void)dumpView:(UIView *)aView atIndent:(int)indent into:(NSMutableString *)outstring | |
{ | |
for (int i = 0; i < indent; i++) [outstring appendString:@"--"]; | |
[outstring appendFormat:@"[%2d] %@\n", indent, [[aView class] description]]; | |
for (UIView *view in [aView subviews]) | |
[self dumpView:view atIndent:indent + 1 into:outstring]; | |
} | |
// Start the tree recursion at level 0 with the root view | |
- (NSString *) displayViews: (UIView *) aView | |
{ | |
NSMutableString *outstring = [[NSMutableString alloc] init]; | |
[self dumpView: self.window atIndent:0 into:outstring]; | |
return [outstring autorelease]; | |
} | |
// Show the tree | |
- (void)logViewTreeForMainWindow | |
{ | |
// CFShow([self displayViews: self.window]); | |
ATLogInfo(@"The view tree:\n%@", [self displayViews:self.window]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment