iOS递归打印UIView的结构

来源:互联网 发布:淘宝闲鱼网二手官网 编辑:程序博客网 时间:2024/05/01 16:41

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];}


0 0
原创粉丝点击