UITableView 单元格选择颜色? [英] UITableView Cell selected Color?
本文介绍了UITableView 单元格选择颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个自定义的 UITableViewCell
.表视图显示数据很好.我遇到的是当用户触摸 tableview 的单元格时,然后我想显示单元格的背景颜色而不是默认的 [blue color] 值以突出显示单元格的选择.我使用此代码但没有任何反应:
I have created a custom UITableViewCell
. The table view is showing data fine. What I am stuck in is when user touches cell of tableview, then I want to show the background color of the cell other than the default [blue color] values for highlighting the selection of cell.
I use this code but nothing happens:
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
推荐答案
无需自定义单元格.如果您只想更改单元格的选定颜色,您可以这样做:
No need for custom cells. If you only want to change the selected color of the cell, you can do this:
目标 C:
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor redColor];
[cell setSelectedBackgroundView:bgColorView];
斯威夫特:
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.red
cell.selectedBackgroundView = bgColorView
这篇关于UITableView 单元格选择颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文