Created
June 11, 2012 14:43
-
-
Save gavingmiller/2910402 to your computer and use it in GitHub Desktop.
Objective-C Dump Views
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
static void dumpViews(UIView* view, NSString *text, 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]; | |
dumpViews(subView, msg, newIndent); | |
[msg release]; | |
[newIndent release]; | |
} | |
} |
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
def dump_views(view, text = "", indent = "") | |
klass = view.class | |
klassDescription = klass.description | |
while klass.superclass | |
klass = klass.superclass | |
klassDescription = klassDescription + ":#{klass.description}" | |
end | |
if text.compare("") == NSOrderedSame | |
puts "#{klassDescription} #{NSStringFromCGRect(view.frame)}" | |
else | |
puts "#{text} #{klassDescription} #{NSStringFromCGRect(view.frame)}" | |
end | |
view.subviews.each_index do |i| | |
subview = view.subviews.objectAtIndex(i) | |
newIndent = " #{indent}" | |
message = "#{newIndent}#{i}" | |
dump_views(subview, message, newIndent) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment