iOS 界面调试神器-给所有子视图加框

//给所有子视图加框

iOS 界面调试神器-给所有子视图加框_第1张图片
image

在 UIView 分类添加方法

/**
 给所有自视图加框
 */
- (void)getViewLayer{
    NSArray *subviews = self.subviews;
    if (subviews.count == 0) return;
    for (UIView *subview in subviews) {
        subview.layer.borderWidth = kW_LayerBorder;
        
        #if DEBUG
        subview.layer.borderColor = UIColor.redColor.CGColor;
        #else
        subview.layer.borderColor = UIColor.clearColor.CGColor;
        #endif
        [subview getViewLayer];
    }
}

//使用方法:
[self.view  getViewLayer];

另分享一个别人的打印所有子视图的方法(出处忘了,对不起)

//控制台打印所有子视图(需要注意的是,我的level设置是从1开始的,这与方法中加空格时变量i起始的值是相呼应的,要改就要都改。)

+ (void)getSub:(UIView*)view andLevel:(NSInteger)level {

  NSArray*subviews = view.subviews;
  if(subviews.count ==0) return;

  for(UIView *subview in subviews) {
   NSString *blank = @"";

    for(NSInteger i = 1; i < level; i++) {
      blank = [NSStringstringWithFormat:@"%@", blank];
    }

    NSLog(@"%@%ld: %@_%@", blank, (long)level,subview.class, NSStringFromCGRect(subview.frame));
    [self getSub:subviewandLevel:(level+1)]; 
  }
}

//使用:
[UIView getSub:alertController.view  andLevel:1];

你可能感兴趣的:(iOS 界面调试神器-给所有子视图加框)