gpt4 book ai didi

ios - 禁用背景颜色更改,但在 UITableViewCell 突出显示时启用文本颜色更改

转载 作者:行者123 更新时间:2023-12-01 17:38:54 24 4
gpt4 key购买 nike

我想让 UITableViewCell 文本颜色在被选中时更改,但仅此而已。我想禁用单元格中的背景突出显示。我看到了如下解决方案:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

但这也会禁用文本颜色更改。我希望以简单的方式实现的那种行为?

最佳答案

在您的 cellForRowAtIndexPath , 做 :

步骤 1. 将您的选择样式设置为默认值。

cell.selectionStyle = UITableViewCellSelectionStyleDefault;

步骤 2. 将空 View 设置为背景 View
UIView *view = [UIView new] ;
[view setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:view];

步骤 3. 设置你想要的文本颜色,比如说
[[cell textLabel] setTextColor:[UIColor orangeColor]];
[[cell textLabel] setHighlightedTextColor:[UIColor blackColor]];

希望这可以帮助。

关于ios - 禁用背景颜色更改,但在 UITableViewCell 突出显示时启用文本颜色更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29230928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com