iOS 打印出视图中全部的子视图的名称

Posted yfceshi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS 打印出视图中全部的子视图的名称相关的知识,希望对你有一定的参考价值。

使用递归:

- (void)listSubviewsOfView:(UIView *)view {

    // Get the subviews of the view
    NSArray *subviews = [view subviews];

    // Return if there are no subviews
    if ([subviews count] == 0) return; // COUNT CHECK LINE

    for (UIView *subview in subviews) {

        // Do what you want to do with the subview
        NSLog(@"%@", subview);

        // List the subviews of subview
        [self listSubviewsOfView:subview];
    }
}

方法转载自:http://stackoverflow.com/a/7244069/3458781

打印结果:

2014-10-10 16:05:14.191 MyAPP[1951:60b] <UIView: 0x16d61a90; frame = (0 64; 320 31); autoresize = RM+BM; layer = <CALayer: 0x16ddb850>>
2014-10-10 16:05:14.192 Vinyo[1951:60b] <UILabel: 0x16d1aa60; frame = (15 70; 210 20); text = 'Choose a credit card'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x16d1c7f0>>





以上是关于iOS 打印出视图中全部的子视图的名称的主要内容,如果未能解决你的问题,请参考以下文章

LiveData 没有观察具有共享视图模型的子视图页面片段

更改recyclerview android的子视图颜色

加载ios后如何扩大视图宽度

SwiftUI中sheet弹出嵌在NavigationView中的子视图无法用presentationMode关闭(dismiss)弹出视图的解决

SwiftUI中Section视图里的文本全部变成大写显示的解决

iOS:父视图覆盖的子视图阴影