遍历subviews

Nsstring *xml = [self digView:self.view];
[xml writetoFile:@"/Users/frankhou/Desktop/view.xml"
      atomically:YES
        encoding:NSUTF8StringEncoding
           error:nil];
- (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;
}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念