您的位置:首页 > 产品设计 > UI/UE

iOS递归打印UIView的结构

2014-02-24 09:52 627 查看
iOS递归打印UIView结构

1、iOS在lldb调试窗口可用recursiveDescription打印该UIView的整个结构,如下:



2、用Objective-C代码实现如下:

+ (NSString *)showViewHierarchy:(UIView *)view level:(NSInteger)level
{
NSMutableString * description = [NSMutableString string];
NSMutableString * indent = [NSMutableString string];
for (NSInteger i = 0; i < level; i++)
{
[indent appendString:@"  |"];
}

[description appendFormat:@"\n%@%@", indent, [view description]];
for (UIView * item in view.subviews)
{
[description appendFormat:@"%@", [UIView showViewHierarchy:item level:level + 1]];
}
return [description copy];
}

//
// 实现view的循环打印
- (NSString *)recursiveDiscription
{
return [UIView showViewHierarchy:self level:0];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: