Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm pretty sure that you can't mask the corners this way. The cell's <code>backgroundView</code> is an image for a grouped <code>UITableView</code> so there's no sense of masking. </p> <p>A possible solution to the problem would be to round the corners yourself. This is a little tricky since you only want to round the top corners of the top cell and the bottom corners of the bottom cell. Fortunately, @lomanf posted a great solution to rounding arbitrary corners here: <a href="https://stackoverflow.com/questions/4847163/round-two-corners-in-uiview/4930166#4930166">Round two corners in UIView</a>. Using his <code>MTDContextCreateRoundedMask</code> method, we can achieve our goal.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Other cell instantiation // First cell in section if (indexPath.row == 0) { [self roundTopOrBottomCornersOfCell:cell top:YES]; } // Last cell in section else if (indexPath.row == tableView.numberOfRowsInSection:indexPath.section-1) { [self roundTopOrBottomCornersOfCell:cell top:NO]; } } // Modified from the second part of @lomanf's Solution 1 - (void)roundTopOrBottomCornersOfCell:(UITableViewCell*)cell top:(BOOL)top { // Set constant radius CGFloat radius = 5.0; // Create the mask image you need calling @lomanf's function UIImage* mask; if (top) { mask = MTDContextCreateRoundedMask(self.view.bounds, radius, radius, 0.0, 0.0); } else { mask = MTDContextCreateRoundedMask(self.view.bounds, 0.0, 0.0, radius, radius); } // Create a new layer that will work as a mask CALayer* layerMask = [CALayer layer]; layerMask.frame = cell.bounds; // Put the mask image as content of the layer layerMask.contents = (id)mask.CGImage; // Set the mask layer as mask of the view layer cell.layer.mask = layerMask; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload