Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johanforssell
Created September 4, 2014 17:45
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 johanforssell/af56eead43351a30859d to your computer and use it in GitHub Desktop.
Save johanforssell/af56eead43351a30859d to your computer and use it in GitHub Desktop.
Simple recursive function for printing a view hierarchy in cocoa touch. Originally from user207616 on Stack Overflow.
// --------------------------------------------------
#import <UIKit/UIKit.h>
@interface UIView (Hierarchy)
- (void)printViewHierarchy;
@end
// --------------------------------------------------
#import "UIView+Hierarchy.h"
@implementation UIView (Hierarchy)
- (void)printViewHierarchy
{
[self _logView:self index:0];
}
#pragma mark - Private
- (void)_logView:(UIView*)v index:(int)i
{
NSMutableString *str = [NSMutableString string];
for (int u = 0; u<i; u++) {
[str appendString:@"| "];
}
[str appendFormat:@"<%@ %p frame:%@>", v.class, v, NSStringFromCGRect(v.frame)];
// of course you can change it to display your accessibility hint/label
printf("%s\n", [str UTF8String]);
for (UIView *vv in v.subviews) {
[self _logView:vv index:i+1];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment