自定义UITableViewCell选择风格? [英] Custom UITableViewCell selection style?

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

问题描述

当我点击我的 UITableViewCell 时,背景部分(我的背景图片不覆盖的区域)在我单击单元格时变为蓝色。此外,单元格上的所有 UILabel 在点击时变为白色,这是我想要的。

When I click on my UITableViewCell, the background part (the areas that my background image doesn't cover) turns blue when I click on the cell. Also, all of the UILabels on the cell turn to white when it is clicked which is what I want.

然而我不想要的是蓝色的背景,当我点击它,但如果我做 selectionstylenone ,那么我失去突出显示的颜色为 UILabel 在单元格中。

However what I do not want is the blue background when I click it but if I do selectionstylenone, then I lose the highlighted colours for the UILabels in the cell.

所以有任何方法来摆脱蓝色背景的单元格被点击,但保持突出显示的颜色 UILabel s?

So is there any way to just get rid of the blue background when the cell is clicked but to keep the highlighted colors of the UILabels?

推荐答案

将您的表格单元格的选择样式设置为 UITableViewCellSelectionStyleNone 。这将删除蓝色背景突出显示。然后,为了使文本标签突出显示工作方式,而不是使用默认的UITableViewCell类,创建 UITableViewCell 的子类,并覆盖<$ c $的默认实现c> setHighlighted:animated 使用自己的实现,根据突出显示的状态设置标签颜色。

You can do this as follows. Set your table cell's selection style to UITableViewCellSelectionStyleNone. This will remove the blue background highlighting. Then, to make the text label highlighting work the way you want, instead of using the default UITableViewCell class, create a subclass of UITableViewCell and override the default implementation of setHighlighted:animated with your own implementation that sets the label colors to however you want depending on the highlighted state.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    if (highlighted) {
        self.textLabel.textColor = [UIColor whiteColor];
    } else {
        self.textLabel.textColor = [UIColor blackColor];
    }
}

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

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