美文网首页
iOS 界面调试神器-给所有子视图加框

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

作者: SoaringHeart | 来源:发表于2017-11-07 16:30 被阅读5次

    //给所有子视图加框

    image
        //给所有子视图加框
    
        + (void)getLineWithView:(UIView *)containView{
    
          NSArray *subviews = [containView subviews];
    
          if ([subviews count] == 0) return;
    
          for (UIView *subview in subviews) {
    
          subview.layer.borderColor = [[UIColor redColor] CGColor];
    
          subview.layer.borderWidth = 0.5;
    
          [self getLineWithView:subview];
    
          }
    
        }
    
    使用方法:
    
        [UIView  getLineWithView:view];
    
    * * *
    
    另分享一个别人的打印所有子视图的方法(出处忘了,对不起😞)
    
        //控制台打印所有子视图(需要注意的是,我的level设置是从1开始的,这与方法中加空格时变量i起始的值是相呼应的,要改就要都改。)
    
        + (void)getSub:(UIView*)view andLevel:(NSInteger)level {
    
          NSArray*subviews = [viewsubviews];
    
          if([subviewscount] ==0)return;
    
          for(UIView*subviewinsubviews) {
    
          NSString*blank =@"";
    
          for(NSIntegeri =1; i < level; i++) {
    
          blank = [NSStringstringWithFormat:@"%@", blank];
    
        }
    
        //NSLog(@"%@%ld: %@", blank, (long)level, subview.class);
    
          NSLog(@"%@%ld: %@_%@", blank, (long)level,subview.class,NSStringFromCGRect(subview.frame));
    
        [selfgetSub:subviewandLevel:(level+1)];
    
          }
    
         }
    
    使用:
    
        [UIView   getSub:alertController.view  andLevel:1];
    
    //给所有子视图加框
    - (void)getViewLayer{
        NSArray *subviews = self.subviews;
        if (subviews.count == 0) return;
        for (UIView *subview in subviews) {
            subview.layer.borderWidth = 1;
            subview.layer.borderColor = UIColor.blueColor.CGColor;
    //        subview.layer.borderColor = UIColor.clearColor.CGColor;
            
            [subview getViewLayer];
            
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 界面调试神器-给所有子视图加框

          本文链接:https://www.haomeiwen.com/subject/kbujmxtx.html