打印ViewTree

查看当前viewtree结构

 

下列代码加入到AppDelegate

 

- (void)dumpView:(UIView *)aView atIndent:(int)indentinto:(NSMutableString *)outstring

{

    for (int i = 0; i< indent; i++) [outstring appendString:@"--"];

    [outstringappendFormat:@"[%2d] %@\n", indent, [[aView class] description]];

    for (UIView *viewin [aView subviews])

        [selfdumpView:view atIndent:indent + 1 into:outstring];

}

 

// Start the tree recursion at level 0 with the root view

- (NSString *) displayViews: (UIView *) aView

{

    NSMutableString*outstring = [[NSMutableString alloc] init];

    [self dumpView:self.window atIndent:0 into:outstring];

    return outstring ;

}

// Show the tree

- (void)logViewTreeForMainWindow

{

    //  CFShow([self displayViews: self.window]);

    NSLog(@"Theview tree:\n%@", [self displayViews:self.window]);

}

 

 

然后在你想使用的地方使用

 

    AppDelegate*a=(AppDelegate *)[[UIApplicationsharedApplication] delegate];

 

    [alogViewTreeForMainWindow];

此时打印的就是 当前的viewtree

如下:

[ 0] UIWindow

--[ 1] UILayoutContainerView

----[ 2] UITransitionView

------[ 3] UIViewControllerWrapperView

--------[ 4] UILayoutContainerView

----------[ 5] UINavigationTransitionView

------------[ 6] UIViewControllerWrapperView

--------------[ 7] UITableView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] UITableViewCell

------------------[ 9] UITableViewCellContentView

--------------------[10] UILabel

--------------------[10] UIImageView

------------------[ 9] UIButton

--------------------[10] UIImageView

------------------[ 9] UIView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------------[ 8] _UITableViewSeparatorView

----------[ 5] UINavigationBar

------------[ 6] UIMoreListController

------------[ 6] UINavigationItemView

------------[ 6] UINavigationButton

--------------[ 7] UIImageView

--------------[ 7] UIButtonLabel

----[ 2] UITabBarCustomizeView

------[ 3] UINavigationBar

--------[ 4] UINavigationBarBackground

--------[ 4] UINavigationItemView

--------[ 4] UINavigationButton

----------[ 5] UIImageView

----------[ 5] UIButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

----[ 2] UITabBar

------[ 3] _UITabBarBackgroundView

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

------[ 3] UITabBarButton

--------[ 4] UITabBarSelectionIndicatorView

--------[ 4] UITabBarSwappableImageView

--------[ 4] UITabBarButtonLabel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值