ios 去除 UITableView 的单元格高亮颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2787093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:12:20  来源:igfitidea点击:

Remove the cell highlight color of UITableView

iosobjective-cuitableview

提问by neha

I want to remove the default blue color of uitableview cell selection. I don't want any selection color there. I have not created a custom cell class. I'm customizing the cell by adding labels and buttons over it. I tried doing:

我想删除 uitableview 单元格选择的默认蓝色。我不想要任何选择颜色。我还没有创建自定义单元格类。我通过在单元格上添加标签和按钮来自定义单元格。我试着做:

cell.selectioncolor = [UIColor clearcolor];

but it says that this method is deprecated.

但它说这种方法已被弃用。

回答by Vladimir

cell.selectionStyle = UITableViewCellSelectionStyleNone;

in Swift 4updated

Swift 4 中更新

cell.selectionStyle = UITableViewCell.SelectionStyle.none

Or

或者

cell.selectionStyle = .none

回答by Michael

Select this in Storyboardor XIB

Storyboard或 中选择此项XIB



enter image description here

在此处输入图片说明

回答by Joey Wong

// Swift 2.0

cell.selectionStyle = UITableViewCellSelectionStyle.None

回答by Rashwan L

Swift 3.0

斯威夫特 3.0

cell.selectionStyle = .none

回答by Frantiesco Masutti

Objective-C:

目标-C:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

或者

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Swift 4:

斯威夫特 4:

self.selectionStyle = UITableViewCellSelectionStyle.none;

Swift 3:

斯威夫特 3:

cell.selectionStyle = .none

Swift 2:

斯威夫特 2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

If you want to change it just using Storyboard/Xib, just select the Cell that you want to remove the "Selection Style Effect" and define it as "None". It'll work like magic as well :D

如果您只想使用 Storyboard/Xib 更改它,只需选择要删除“选择样式效果”的单元格并将其定义为“无”。它也会像魔术一样工作:D

Storyboard / Xib

故事板 / Xib

回答by lynchspin

Setting the TableView Selection style to .nonewas affecting the responsiveness and performance of the tableview in my app (didSelectRowAt indexPathtaps were getting delayed). My solution to this problem was to hide the selected background view on awakeFromNib()when the cell is first created:

将 TableView 选择样式设置.none为会影响我的应用程序中 tableview 的响应能力和性能(didSelectRowAt indexPath点击被延迟)。我对这个问题的解决方案awakeFromNib()是在首次创建单元格时隐藏选定的背景视图:

selectedBackgroundView?.isHidden = true

selectedBackgroundView?.isHidden = true

回答by Jugal K Balara

Try this for swift

试试这个快速

cell?.selectionStyle = UITableViewCellSelectionStyle.None

回答by Zgpeace

swift 5

迅捷 5

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

        return cell
    }