// 遞歸獲取子視圖spa
- (void)getSub:(UIView *)view andLevel:(int)level {orm
NSArray *subviews = [view subviews];遞歸
// 若是沒有子視圖就直接返回get
if ([subviews count] == 0) return;string
for (UIView *subview in subviews) {it
// 根據層級決定前面空格個數,來縮進顯示class
NSString *blank = @"";view
for (int i = 1; i < level; i++) {vi
blank = [NSString stringWithFormat:@" %@", blank];co
}
// 打印子視圖類名
NSLog(@"%@%d: %@", blank, level, subview.class);
// 遞歸獲取此視圖的子視圖
[self getSub:subview andLevel:(level+1)];
}
}