UITableView Cell选择了Color? [英] UITableView Cell selected Color?

查看:126
本文介绍了UITableView Cell选择了Color?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义 UITableViewCell 。表格视图显示数据正常。我坚持的是当用户触摸tableview的单元格时,我想显示除默认[蓝色]值以外的单元格的背景颜色,以突出显示单元格的选择。
我使用此代码但没有任何反应:

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];


推荐答案

我认为你走在正确的轨道上,但根据到的类定义selectedBackgroundView

I think you were on the right track, but according to the class definition for selectedBackgroundView:


普通单元格的默认值为nil样式表(UITableViewStylePlain)和非零用于部分组表UITableViewStyleGrouped)。

The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables UITableViewStyleGrouped).

因此,如果你使用的是平原样式表,然后你需要alloc-init一个新的 UIView 具有你想要的背景颜色然后分配给 selectedBackgroundView

Therefore, if you're using a plain-style table, then you'll need to alloc-init a new UIView having your desired background colour and then assign it to selectedBackgroundView.

或者,您可以使用:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

如果您选择单元格时所有想要的是灰色背景。希望这会有所帮助。

if all you wanted was a gray background when the cell is selected. Hope this helps.

这篇关于UITableView Cell选择了Color?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆