Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionViewCell上的自定义图形_Ios_Core Graphics_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionViewCell上的自定义图形

Ios UICollectionViewCell上的自定义图形,ios,core-graphics,uicollectionviewcell,Ios,Core Graphics,Uicollectionviewcell,我想在UICollectionView中的每个UICollectionViewCell上添加网格。以下是我试图做的: - (void) drawRect:(CGRect)rect{ int width = rect.size.width; int height = rect.size.height; int i = 0; [[UIColor blackColor] setStroke]; UIBezierPath* drawingPath = [UIB

我想在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];
}
-(void)drawRect:(CGRect)rect{
int width=rect.size.width;
int height=rect.size.height;
int i=0;
[[UIColor blackColor]设定行程];
UIBezierPath*drawingPath=[UIBezierPath bezierPath];

对于(i=0;i图像中的一个单元格是什么?每个单元格都是一个数字吗?我试过你的代码,它对我来说很好。@rdelmar每个数字都是一个单元格。这很奇怪。@rdelmar我设置它的方式是我用这个
drawRect
方法创建了一个BackgroundView类。然后我将每个单元格的BackgroundView属性设置为Bac的初始化副本kgroundView类。你是这样做的吗?不,我只是把你的代码放到我的UICollectionViewCell子类的.m文件中。我最初是这样做的,结果和我最初的问题一样。