Created
September 4, 2014 17:45
-
-
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.
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
// -------------------------------------------------- | |
#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