0

我知道它可能是重复的,但我想知道在选择单元格时更改蓝色突出显示颜色的最佳和最快方法。

诅咒,我已经尝试过(并且它有效)选择单元格时更改背景颜色的方式(如this thread)但我不喜欢这种方式,我更愿意真正改变这个突出显示颜色。

任何链接或想法?谢谢。

4

5 回答 5

7

在tableview里面

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

创建一个 uiimageview 并将其背景颜色更改为您想要的颜色

if (cell == nil) {
    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor greenColor];
    cell.selectedBackgroundView = bgView;
}
于 2013-05-22T08:42:25.027 回答
2

如果您使用 nib 创建表格视图单元格,那么在单元格的属性检查器中,您可以看到一个属性“选择”。将此设置为无。

如果您以编程方式创建,则将您的单元格设置为

yourCell.selectionStyle = UITableViewCellEditingStyleNone;
于 2013-05-22T08:48:42.363 回答
0

在这个方法中写下这些行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath



if (cell == nil) 
{
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];

    UIImageView *bgView = [[UIImageView alloc]initWithFrame:cell.frame];
    bgView.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView  = bgView;
}
于 2013-05-22T08:51:49.130 回答
0

首先,您必须创建一个与单元格大小相同的视图。将背景颜色应用于该视图。然后在 cellForRowAtIndexpath 委托方法中将视图设置为单元格的选定背景。

[cell setSelectedBackgroundView:yourView];
于 2013-05-22T08:43:51.163 回答
0

您可以将新的 UIView 分配给具有所需颜色的单元格的 selectedBackgroundView。 斯威夫特 3

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "departmentCell", for: indexPath)

        let selectedView = UIView(frame: cell.frame)
        selectedView.backgroundColor = ColorKit.cellSelectionColor
        cell.selectedBackgroundView = selectedView



        return cell
    }
于 2017-03-09T07:32:39.593 回答