Skip to content

Instantly share code, notes, and snippets.

@ourui
Last active December 23, 2015 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourui/6b8c7760851c69b8f80b to your computer and use it in GitHub Desktop.
Save ourui/6b8c7760851c69b8f80b to your computer and use it in GitHub Desktop.
Recursively Print UIView Hierarchy
//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