1
我有一个自定义的UITableViewCell。厦门国际银行的文件看起来是这样的:与自定义单元格/自定义背景图像分组的UITableView
细胞可以通过选择它来打开和关闭。当单元格关闭时,只有标题标签和顶部背景图像可见。下面是表视图看起来像在模拟器上,打开和关闭:
我试图弄清楚如何处理圆角。目前,我检查,看看是否该小区是第一,最后或中间细胞,并应用口罩:
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;
}
但正如你所看到的,它不是做为底电池相当的工作 - 在表格视图的边界被遮挡。
我该如何解决这个问题?