美文网首页ios
iOS 给View添加网格线

iOS 给View添加网格线

作者: 广锅锅 | 来源:发表于2016-06-20 10:16 被阅读733次
    - (void)addGrid:(UIView *)view {
        CGFloat widthView = view.frame.size.width;
        CGFloat heightView = view.frame.size.height;
        CGFloat size = 50;
        
        void (^addLineWidthRect)(CGRect rect) = ^(CGRect rect) {
            CALayer *layer = [[CALayer alloc] init];
            [view.layer addSublayer:layer];
            layer.frame = rect;
            layer.backgroundColor = [[UIColor redColor] CGColor];
        };
        
        for (int i=0; i<widthView; i+=size) {
            addLineWidthRect(CGRectMake(i, 0, 1, heightView));
        }
        for (int i=0; i<heightView; i+=size) {
            addLineWidthRect(CGRectMake(0, i, widthView, 1));
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS 给View添加网格线

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