gpt4 book ai didi

ios - 无法更改 UITableView 蓝色突出显示颜色

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:18 27 4
gpt4 key购买 nike

我设置:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

并使用代码高亮一行:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone

高亮颜色总是蓝色,即使我设置为灰色。如果我设置:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

它工作正常,没有亮点。但只是不能使用:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

它只显示蓝色而不是灰色。任何想法?谢谢。

最佳答案

实现如下:-

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {

[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}

selectedBackgroundView 的颜色设置为您在自定义 tableview 单元格(它是 UITableViewCell 的子类)中想要的颜色:

UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];

或者你可以在-tableView:cellForRowAtIndexPath:方法中配置:

//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...

关于ios - 无法更改 UITableView 蓝色突出显示颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18019834/

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