用递归方式拼接view的层次结构

- (void)dumpView:(UIView *)aView atIndent:(int)indent into:(NSMutableString *)outstring

{
    
    for (int i = 0; i < indent; i++) [outstring appendString:@"--"];
    
    [outstring appendFormat:@"[%2d] %@\n", indent, [[aView class] description]];
    
    for (UIView *view in [aView subviews])
        
        [self dumpView:view atIndent:indent + 1 into:outstring];
    
}

- (NSString *) displayViews: (UIView *) aView

{
    
    NSMutableString *outstring = [[NSMutableString alloc] init];
    
    [self dumpView: aView atIndent:0 into:outstring];
    
    return outstring;
    
}

 

 

//调用displayView既可

posted @ 2013-06-12 13:06  cqclassic  阅读(162)  评论(0编辑  收藏  举报