1

我有一个自定义 UITableViewCell。xib 文件如下所示:

在此处输入图像描述

可以通过选择它来打开和关闭单元格。当单元格关闭时,只有标题标签和顶部背景图像可见。这是模拟器上的表格视图,打开和关闭的样子:

在此处输入图像描述 在此处输入图像描述

我试图弄清楚如何处理圆角。目前,我正在检查单元格是第一个单元格、最后一个单元格还是中间单元格,并应用蒙版:

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;
}

但正如您所看到的,它对底部单元格不起作用 - 表格视图的边框被遮挡了。

我怎么解决这个问题?

4

1 回答 1

1

看起来您只需将表格视图的分隔符样式设置为“单线”(UITableViewCellSeparatorStyleSingleLine)而不是“单线蚀刻”。

于 2012-10-26T18:43:35.430 回答