// 递归方法获取子视图
- (void)getSubview:(UIView *)view level:(int)level {
NSArray *subviews = [view subviews];
if ([subviews count] == 0) return;
for (UIView *subview in subviews) {
NSString *blank = @"";
for (int i = 1; i < level; i++) {
blank = [NSString stringWithFormat:@" %@", blank];
}
NSLog(@"====%@%d: %@", blank, level, subview.class);
[self getSubview:subview level:(level + 1)];
}
}
调用:
[self getSubview:self.navigationController.navigationBar level:1];
打印结果:
导航栏子视图
网友评论