title: How to avoid color blending while drawing rectangles?
body: <p>While drawing rectangles in a UIView for ios I keep having the same issue: the rectangle margins blend their color with the background. I tried several rectangle drawing methods with the same results — using a bezier path, drawing line by line, drawing the margins and filling up the insides of the rectangle.</p>
  
  <p>The view's frame's themselves are always correctly draw. I've even considered using views whenever I need a rectangle, but that doesn't seem like the correct way to do things specially because I need to draw many of them.</p>
  
  <p>Here is an example of my problem. For comparison, I'm drawing a rectangular green view with the same dimensions:</p>
  
  <pre><code>CGRect horizontalBar = CGRectMake(2, 2, 10, 6);
  
  UIView* horizontalBarSubView = [[UIView alloc] initWithFrame:horizontalBar];
  horizontalBarSubView.backgroundColor = [UIColor greenColor];
  [self addSubview:horizontalBarSubView];
  [horizontalBarSubView release];
  </code></pre>
  
  <p>And for the rectangle itself:</p>
  
  <pre><code>CGRect horizontalBar = CGRectMake(2, 20, 10, 6);
  
  UIBezierPath* horizontalBarPath = [UIBezierPath bezierPathWithRect:horizontalBar];
  [[UIColor greenColor] set];
  [horizontalBarPath fill];
  </code></pre>
  
  <p>This wields the following result (10x zoom):</p>
  
  <p><img src="https://i.stack.imgur.com/wN8dN.png" alt="10x zoom rectangle test"></p>
  
  <p><strong>What is causing the colors to blend?</strong></p>
  
  <p><strong>How can I avoid this?</strong></p>