Skip to content

Instantly share code, notes, and snippets.

@SmallBlackCat
Last active August 29, 2015 14:05
Show Gist options
  • Save SmallBlackCat/cca2c8284087539919a9 to your computer and use it in GitHub Desktop.
Save SmallBlackCat/cca2c8284087539919a9 to your computer and use it in GitHub Desktop.
查看当前view tree结构
// Frome http://poolo.iteye.com/blog/1833821
#import <UIKit/UIKit.h>
@interface UIView (Tree)
- (void)logViewTreeForMainWindow;
@end
#import "UIView+Tree.h"
// Frome http://poolo.iteye.com/blog/1833821
@implementation UIView (Tree)
- (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 ;
}
// Show the tree
- (void)logViewTreeForMainWindow
{
// CFShow([self displayViews: self.window]);
NSLog(@"The view tree:\n%@", [self displayViews:self.window]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment