无法更改UITableView蓝色突出显示颜色 [英] Cannot change UITableView blue highlight color

查看:95
本文介绍了无法更改UITableView蓝色突出显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

并使用代码突出显示一行:

and use the code to highlight a row:

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

即使我设置为灰色,突出显示颜色也始终是蓝色.如果我设置了

The highlight color always blue even I set to gray. If I set:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

它工作正常并且没有突出显示.但不能使用:

it works fine and no highlight. But just not work with:

cell.selectionStyle = UITableViewCellSelectionStyleGray;

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

It just show blue color instead of gray color. Any idea? Thanks.

推荐答案

实施如下:-

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

     [cell setSelectionStyle:UITableViewCellSelectionStyleGray];       
}

OR

根据需要在自定义表格视图单元格(UITableViewCell的子类)中设置selectedBackgroundView的颜色:

Set the selectedBackgroundView's color as what you want in your custom tableview cell (which is a subclass of UITableViewCell):

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

,或者您可以使用-tableView:cellForRowAtIndexPath:方法对其进行配置:

or you can configure it in -tableView:cellForRowAtIndexPath: method:

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

这篇关于无法更改UITableView蓝色突出显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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