12.18打印view中所有的子类

//给出一个view打印它的子控件

- (NSString *)digView:(UIView *)view

{

    if ([view isKindOfClass:[UITableViewCell class]]) return @"";

    // 1.初始化

    NSMutableString *xml = [NSMutableString string];

    

    // 2.标签开头

    [xml appendFormat:@"<%@ frame=\"%@\"", view.class, NSStringFromCGRect(view.frame)];

    if (!CGPointEqualToPoint(view.bounds.origin, CGPointZero)) {

        [xml appendFormat:@" bounds=\"%@\"", NSStringFromCGRect(view.bounds)];

    }

    

    if ([view isKindOfClass:[UIScrollView class]]) {

        UIScrollView *scroll = (UIScrollView *)view;

        if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, scroll.contentInset)) {

            [xml appendFormat:@" contentInset=\"%@\"", NSStringFromUIEdgeInsets(scroll.contentInset)];

        }

    }

    

    // 3.判断是否要结束

    if (view.subviews.count == 0) {

        [xml appendString:@" />"];

        return xml;

    } else {

        [xml appendString:@">"];

    }

    

    // 4.遍历所有的子控件

    for (UIView *child in view.subviews) {

        NSString *childXml = [self digView:child];

        [xml appendString:childXml];

    }

    

    // 5.标签结尾

    [xml appendFormat:@"</%@>", view.class];

    

    return xml;

}

 

posted @ 2015-12-18 17:02  张凯泽  阅读(188)  评论(0编辑  收藏  举报