前端之家收集整理的这篇文章主要介绍了
遍历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 @"";
NSMutableString *xml = [NSMutableString string];
[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)];
}
}
if (view.subviews.count == 0) {
[xml appendString:@" />"];
return xml;
} else {
[xml appendString:@">"];
}
for (UIView*child in view.subviews) {
NSString *childXml = [self digView:child];
[xml appendString:childXml];
}
[xml appendFormat:@"</%@>",view.class];
return xml;
}