title: Custom Graphics on UICollectionViewCell
body: <p>I want to add a grid on each UICollectionViewCell in my UICollectionView. Here is what I tried to do:</p>
  
  <pre><code>- (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 &lt;= 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 &lt;= height ; i += height/3) {
          [drawingPath moveToPoint:CGPointMake(0,i)];
          [drawingPath addLineToPoint:CGPointMake(width, i)];
      }
      [drawingPath stroke];
  }
  </code></pre>
  
  <p>However, I end up with something that looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/oOvo4.png" alt="Screenshot"></p>
  
  <p>The other thing is that I want to color in certain squares in the grid. Is there any simple way of doing that without creating additional subviews? Thanks for all the help!</p>