0

I know this is a usual problem, but I haven't seen any solution to this, hence this thread.

We've all create a grouped UITableView and tried to set the cell.imageView to a image. But what happends? The first and the last cell gets ugly because they're rectangular.

What we want to do is to only round the top left corner of the image in the first row and bottom left of the image in the last row.

A method like this:

cell.imageView.image = [image setCornerRadiusLeftTop: 10.0 rightTop: 0 leftBottom: 0 rightBottom: 0];`

Is there anybody out there that has done something similar?

Fernando Redondo
  • 1,557
  • 3
  • 20
  • 38
  • I think you'll find method you're looking for in the response to this question: [Just two rounded Corners?](http://stackoverflow.com/questions/4845211/just-two-rounded-corners). I've gotten great results using it. You can thank kevboh. – salo.dm Nov 09 '11 at 10:23
  • Glad you worked it out. That's a nice little method you posted. – salo.dm Nov 12 '11 at 08:06

2 Answers2

0

One solution would be to use a layer mask:

cell.imageView.layer.mask = layerMask;

You would need two masks: one for the top, one for the bottom cells. You can use a CAShapeLayer to create such a mask.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
0

Solution:

+ (CAShapeLayer *) roundedCornerOnImage: (UIImageView *)imageView onCorner: (UIRectCorner)rectCorner
{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds 
                                                   byRoundingCorners:rectCorner
                                                         cornerRadii:CGSizeMake(10.0, 10.0)];

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = imageView.bounds;
    maskLayer.path = maskPath.CGPath;

    return maskLayer;
}

Example of usage on a imageview in a UITableViewCell:

if (indexPath.row == 0)
    cell.imageView.layer.mask = [Helper roundedCornerOnImage:cell.imageView onCorner:UIRectCornerTopLeft];
else if (indexPath.row == self.arrayPeople.count - 1)
    cell.imageView.layer.mask = [Helper roundedCornerOnImage:cell.imageView onCorner:UIRectCornerBottomLeft];
Fernando Redondo
  • 1,557
  • 3
  • 20
  • 38