Created
April 5, 2012 11:49
-
-
Save PiotrCzapla/2310280 to your computer and use it in GitHub Desktop.
Dump view hierarchy to NSLog
This file contains hidden or 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 <Foundation/Foundation.h> | |
@interface DebugUtils : NSObject | |
/** | |
* Dump view hierarchy to NSLog | |
*/ | |
+ (void) dumpViews:(UIView*)view; | |
@end |
This file contains hidden or 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
// code based on http://stackoverflow.com/questions/289441/uinavigationcontroller-title-can-be-some-image/428434#428434 | |
#import "DebugUtils.h" | |
@implementation DebugUtils | |
+ (void) dumpViews:(UIView*) view label:(NSString *) text indent:(NSString*) indent{ | |
Class cl = [view class]; | |
NSString *classDescription = [cl description]; | |
while ([cl superclass]) { | |
cl = [cl superclass]; | |
classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]]; | |
} | |
if ([text compare:@""] == NSOrderedSame) { | |
NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame)); | |
} else { | |
NSLog(@"%@ %@ %@", text, classDescription, NSStringFromCGRect(view.frame)); | |
} | |
for (NSUInteger i = 0; i < [view.subviews count]; i++) | |
{ | |
UIView *subView = [view.subviews objectAtIndex:i]; | |
NSString *newIndent = [[NSString alloc] initWithFormat:@" %@", indent]; | |
NSString *msg = [[NSString alloc] initWithFormat:@"%@%d:", newIndent, i]; | |
[DebugUtils dumpViews:subView label:msg indent:newIndent]; | |
} | |
} | |
+ (void) dumpViews:(UIView*) view { | |
[DebugUtils dumpViews:view label:@"" indent:@""]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment