0

我想在我的 UICollectionView 中的每个 UICollectionViewCell 上添加一个网格。这是我试图做的:

- (void) drawRect:(CGRect)rect{
    int width = rect.size.width;
    int height = rect.size.height;

    int i = 0;

    [[UIColor blackColor] setStroke];
    UIBezierPath* drawingPath = [UIBezierPath bezierPath];
    for( i = 0 ; i <= width ; i += width/3) {
        [drawingPath moveToPoint:CGPointMake(i, 0)];
        [drawingPath addLineToPoint:CGPointMake(i, height)];
        NSLog(@"width:%d, height:%d", height, i);
    }
    for( i = 0 ; i <= height ; i += height/3) {
        [drawingPath moveToPoint:CGPointMake(0,i)];
        [drawingPath addLineToPoint:CGPointMake(width, i)];
    }
    [drawingPath stroke];
}

但是,我最终得到如下所示的东西:

截屏

另一件事是我想在网格中的某些正方形上着色。有什么简单的方法可以在不创建额外子视图的情况下做到这一点?感谢所有的帮助!

4

0 回答 0