我设置:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
并使用代码突出显示一行:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone
即使我设置为灰色,高光颜色始终为蓝色.如果我设置:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
它工作正常,没有突出显示.但是不能合作:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
它只显示蓝色而不是灰色.任何的想法?谢谢.
ico*_*ter 30
实施如下: -
- (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];
//...
Ver*_*sen 15
请注意,在iOS 7中,使用
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
将无法按预期工作,因为在iOS 7中,即使您传递上面的常量,它现在也是灰色的.看到:
只需将其添加到您的方法中即可
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
....
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez
bgColorView.layer.masksToBounds = YES;
cell.selectedBackgroundView = bgColorView;
....
return cell;
}
如果您有任何疑问,请随时提问
| 归档时间: | 
 | 
| 查看次数: | 14659 次 | 
| 最近记录: |