UITableViewCell - 如何设置选择剪辑?

时间:2023-01-27 23:16:38

In my app, I have a UITableView and each UITableViewCell utilizes a custom background and style with the following code in the "WillDisplayCell" method:

在我的应用程序中,我有一个UITableView,每个UITableViewCell都使用自定义背景和样式,并在“WillDisplayCell”方法中使用以下代码:

UIImage *cellBackgroundImage = [UIImage imageNamed:@"TableView_Cell_Background_iPhone"];

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:cellBackgroundImage     highlightedImage:cellBackgroundImage];

[cell setBackgroundView:backgroundImage];

[backgroundImage release];

The problem is that the PNG I'm using as the background is a rectangle, but the UITableViewCell is a rounded rectangle with a specific layer radius property. When I select a cell, the background overrides the rounded nature of the cell and I get a jarring blue highlighted sharp rectangle. Is there a way to set the selected state corner radius or something along those lines? My only other option if not would be to create a PNG background that fits the rounded rectangle perfectly.

问题是我用作背景的PNG是一个矩形,但UITableViewCell是一个带有特定图层半径属性的圆角矩形。当我选择一个单元格时,背景会覆盖单元格的圆形特性,我会得到一个刺耳的蓝色突出显示的尖锐矩形。有没有办法设置选定的状态角半径或沿这些线的东西?我唯一的另一个选择是创建一个完全适合圆角矩形的PNG背景。

Thanks.

1 个解决方案

#1


1  

I would set the selectionStyle of the cell to UITableViewCellSelectionStyleNone, this stops the blue highlight. Then start to do a custom selection job.

我将单元格的selectionStyle设置为UITableViewCellSelectionStyleNone,这将停止蓝色突出显示。然后开始做自定义选择工作。

You will have to make a custom subclass of UITalbeViewCell. Override setSelected or if that doesn't work user a gesture recognizer or override touchesBegan etc. I have done it once, before, I forget exactly how, if you have trouble let me know and ill look it up.

您必须创建UITalbeViewCell的自定义子类。覆盖setSelected或者如果不起作用,则使用手势识别器或覆盖touchesBegan等。我曾经做过一次,之前,我忘了如何,如果你有麻烦让我知道并生病了。

When you detect that the cell is selected, perhaps create a translucent overlay as a PNG and make it appear when the cell is selected. Alternatively lower the transparency of the background image or add a color mask.

当您检测到单元格被选中时,可能会创建一个半透明叠加层作为PNG,并在选择单元格时显示它。或者降低背景图像的透明度或添加颜色蒙版。

#1


1  

I would set the selectionStyle of the cell to UITableViewCellSelectionStyleNone, this stops the blue highlight. Then start to do a custom selection job.

我将单元格的selectionStyle设置为UITableViewCellSelectionStyleNone,这将停止蓝色突出显示。然后开始做自定义选择工作。

You will have to make a custom subclass of UITalbeViewCell. Override setSelected or if that doesn't work user a gesture recognizer or override touchesBegan etc. I have done it once, before, I forget exactly how, if you have trouble let me know and ill look it up.

您必须创建UITalbeViewCell的自定义子类。覆盖setSelected或者如果不起作用,则使用手势识别器或覆盖touchesBegan等。我曾经做过一次,之前,我忘了如何,如果你有麻烦让我知道并生病了。

When you detect that the cell is selected, perhaps create a translucent overlay as a PNG and make it appear when the cell is selected. Alternatively lower the transparency of the background image or add a color mask.

当您检测到单元格被选中时,可能会创建一个半透明叠加层作为PNG,并在选择单元格时显示它。或者降低背景图像的透明度或添加颜色蒙版。