Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouped UITableView with custom cells / custom background images
    text
    copied!<p>I have a custom UITableViewCell. The xib file looks like this:</p> <p><img src="https://i.stack.imgur.com/MPpmo.png" alt="enter image description here"></p> <p>The cell can be opened and closed by selecting it. When the cell is closed, only the Title Label and the Top Background Image are visible. Here is what the table view looks like on the simulator, open and closed:</p> <p><img src="https://i.stack.imgur.com/oX7za.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/bWvAw.png" alt="enter image description here"></p> <p>I am trying to figure out how to deal with the rounded corners. Currently, I am checking to see if the cell is the first, last or a middle cell, and applying a mask:</p> <pre><code>if (row == 0) { // Create the path (with only the top corners rounded) UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = cell.titleBackgroundImageView.bounds; maskLayer.path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image view's layer cell.titleBackgroundImageView.layer.mask = maskLayer; cell.bodyBackgroundImageView.layer.mask = nil; } else if ((row + 1) == [itemsForSection count]) { // Create the path (with only the bottom corners rounded) UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.titleBackgroundImageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; // Create the shape layer and set its path BOOL isOpened = [[[self.cellOpenedStatusMutableDictionary objectForKey:sectionTitle] objectAtIndex:row] boolValue]; if (isOpened) { cell.titleBackgroundImageView.layer.mask = nil; } else { maskLayer.frame = cell.titleBackgroundImageView.bounds; maskLayer.path = maskPath.CGPath; cell.titleBackgroundImageView.layer.mask = maskLayer; } // Create the path (with only the bottom corners rounded) maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.bodyBackgroundImageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)]; // Create the shape layer and set its path maskLayer = [CAShapeLayer layer]; maskLayer.frame = cell.titleBackgroundImageView.bounds; maskLayer.path = maskPath.CGPath; cell.bodyBackgroundImageView.layer.mask = maskLayer; } else { cell.titleBackgroundImageView.layer.mask = nil; cell.bodyBackgroundImageView.layer.mask = nil; } </code></pre> <p>But as you can see, it doesn't quite work for the bottom cell - the border of the table view is obscured. </p> <p>How can I solve this problem?</p>
 

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