Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Considering you can have multiple groups in your table, some cells are rounding in just in the top corners, other just in the bottom, and others are not rounded. So I created here really fast a subclass (that can be really shortened) of UITableViewCell with the following methods:</p> <p>A property that you can call anything you want, I called Top and Down:</p> <pre><code>@property(nonatomic,assign) BOOL top,down; </code></pre> <p>The implementation:</p> <pre><code>- (void)layoutSubviews { [super layoutSubviews]; if(self.top &amp;&amp; self.down) { self.layer.cornerRadius = 10; self.layer.masksToBounds = YES; return; } if (self.top) { CAShapeLayer *shape = [[CAShapeLayer alloc] init]; shape.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)].CGPath; self.layer.mask = shape; self.layer.masksToBounds = YES; return; } if (self.down) { CAShapeLayer *shape = [[CAShapeLayer alloc] init]; shape.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)].CGPath; self.layer.mask = shape; self.layer.masksToBounds = YES; } } </code></pre> <p>To use is simple, if your cell is the first of a group, set TOP = True, if is the last, DOWN = true, if the cell is the only on the group, TOP and DOWN = true.</p> <p>If you want more or less rounded, just change the radios from 10 to the other value.</p> <p>That is it, you can make it shorter avoiding repetition of code, or using CAShapeLayer in all cases, anyway I hope it helps.</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