title: Clear answer on how to Mask a UIView as a UITableViewCell selectedBackgroundView
body: <p>I've read and tried a few answers I have found on StackOverflow. I've also read and tried a few things from blogs, but nothing seems to accomplish what I am looking for.</p>
  
  <p>I create a <code>UIView</code> and set it's background color to my desired <code>UITableViewCell</code> selection color <em>(instead of the standard blue or gray selection colors)</em>. I add this <code>UIView</code> to my cell's <code>selectedBackgroundView</code> and this works fine, my cell changes to the desired color on user selection.</p>
  
  <p>This method works great on Plain <code>UITableViews</code>; not so well on Grouped. On a grouped <code>UITableView</code>, the 1st and last cell do not conform to clip / mask bounds as demonstrated in the below screenshots.</p>
  
  <p>I know there is no way to round just the top-left and top-right corners only.</p>
  
  <p>I want to do this strictly by code, without images. </p>
  
  <h2>Question</h2>
  
  <p><strong>Does anyone know of a nice little work around to change the <code>selectedBackgroundView</code> color of a <code>UITableViewCell</code> using only the <code>UIView</code> and not images AND to make the 1st and last cell conform to the rounded corner boundaries?</strong></p>
  
  <h1>Example</h1>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString * CellIdentifier = @"Cell";
      WCSBadgedCell   * cell = [[WCSBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle andBadgeStyle:0 reuseIdentifier:CellIdentifier]; 
      if (cell == nil) {
          cell = [[WCSBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault andBadgeStyle:0 reuseIdentifier:CellIdentifier];
      }
  
      UIView *bgColorView = [[UIView alloc] init];
      [bgColorView setBackgroundColor:DARKBROWN];
      [bgColorView setClipsToBounds: YES];
      [cell.layer setMasksToBounds:YES];
      [cell setSelectedBackgroundView:bgColorView];
  
      [cell.textLabel setText: @"Testing a Cell"];
  
      return cell;
  }
  </code></pre>
  
  <h2>Screenshots</h2>
  
  <p><img src="https://i.stack.imgur.com/Tbv3s.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/6IBD4.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/s0XPK.png" alt="enter image description here"></p>
  
  <h2>Solution</h2>
  
  <p>I Accepted <a href="https://stackoverflow.com/a/10219699/171206">CodaFis answer</a> because he added a comment which pointed to a pretty nice <em>(yet lengthy)</em> solution. I had to do quite a bit of revamping, but in the end, I now have the selectedBackgroundView's I needed which round the corners on the 1st and last cells, thanks again!</p>
  
  <p><a href="http://pastie.org/3814006" rel="nofollow noreferrer">Here is a n example of how I achieved this.</a></p>