我正在尝试编写一个文本文件,其中包含屏幕中包含的所有视图的名称。例如,我有一个UIView
,其中有 2 个UIButtons
,所以文件应该如下所示。
UIWindow
UIView
UIButton
UIButtonLabel
UIButton
UIButtonLabel
_UILayoutGuide
_UILayoutGuide
这就是我想要做的,但我无法实现上述层次结构。
-(void) writeViewHierarchyForView:(UIView *)aView inString:( NSMutableString *)str
{
//NSMutableString *str = [[NSMutableString alloc] init];
NSLog(@"title Text = %@", aView.titleText);
if(nil == aView.children){
[str appendString:@"\n"];
return;
}
else{
for(UIView *view in aView.subview){
[str appendString:@"\n\t"];
[str appendString:view.name];
NSLog(@"%@",view.name);
[str appendString:@"\t"];
[self writeViewHierarchyForView:view inString:str];
}
}
}
这不是我在任何项目中使用的东西,只是为了好玩。任何建议都会很棒。