Skip to content

Instantly share code, notes, and snippets.

@atnan
Created July 14, 2009 05:58
Show Gist options
  • Save atnan/146746 to your computer and use it in GitHub Desktop.
Save atnan/146746 to your computer and use it in GitHub Desktop.
@interface UIView (Debugging)
-(void)inspectWithDepth:(int)depth path:(NSString *)path;
@end
@implementation UIView (Debugging)
-(void)inspectWithDepth:(int)depth path:(NSString *)path {
if (depth == 0) {
NSLog(@"-------------------- VIEW HIERARCHY -------------------");
}
NSString* padding = [@"" stringByPaddingToLength:depth withString:@" " startingAtIndex:0];
NSLog([NSString stringWithFormat:@"%@.description: %@", padding, [self description]]);
if ([self isKindOfClass:[UIImageView class]]) {
NSLog([NSString stringWithFormat:@"%@.class: UIImageView", padding]);
} else if ([self isKindOfClass:[UILabel class]]) {
NSLog([NSString stringWithFormat:@"%@.class: UILabel", padding]);
NSLog([NSString stringWithFormat:@"%@.text: ", padding, [(UILabel*)self text]]);
} else if ([self isKindOfClass:[UIButton class]]) {
NSLog([NSString stringWithFormat:@"%@.class: UIButton", padding]);
NSLog([NSString stringWithFormat:@"%@.title: ", padding, [(UIButton*)self titleForState:UIControlStateNormal]]);
}
NSLog([NSString stringWithFormat:@"%@.frame: %.0f, %.0f, %.0f, %.0f", padding, self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height]);
NSLog([NSString stringWithFormat:@"%@.subviews: %d", padding, [self.subviews count]]);
NSLog(@" ");
for (int i = 0; i < [self.subviews count]; i++) {
NSString *subviewPath = [NSString stringWithFormat:@"%@/%d", path, i];
NSLog([NSString stringWithFormat:@"%@--subview-- %@", padding, subviewPath]);
[[self.subviews objectAtIndex:i] inspectWithDepth:(depth + 1) path:subviewPath];
}
if (depth == 0) {
NSLog(@"-------------------- END VIEW HIERARCHY -------------------");
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment