gpt4 book ai didi

iphone - iOS 上 View 层级的可视化

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:53 25 4
gpt4 key购买 nike

在开发 iOS 应用程序时,我发现在调试器中使用 po [[UIWindow keyWindow] recursiveDescription] 非常有用。但是,我想知道是否有一种工具可以优雅地表示输出以提高可读性?

最佳答案

这是我以前写的一个方法:

- (void)logView:(UIView*)v index:(int)i
{
NSMutableString *str = [NSMutableString string];
for (int u = 0; u<i; u++) { [str appendString:@"| "]; }
[str appendFormat:@"<%@ %p frame:%@>", v.class, v, NSStringFromCGRect(v.frame)];
// of course you can change it to display your accessibility hint/label
printf("%s\n", [str UTF8String]);

for (UIView *vv in v.subviews) { [self logView:vv index:i+1]; }
}

这样调用:[self logView:myView index:0];

示例输出:

<UITextField 0x6b30010 frame:{{20, 13}, {280, 31}}>
| <UITextFieldRoundedRectBackgroundView 0x6b31e00 frame:{{0, 0}, {280, 31}}>
| | <UIImageView 0x6b31fe0 frame:{{0, 0}, {0, 0}}>
| | <UIImageView 0x6b32070 frame:{{0, 0}, {0, 0}}>
| | <UIImageView 0x6b320e0 frame:{{0, 0}, {0, 0}}>

关于iphone - iOS 上 View 层级的可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11687519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com