Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 更改UITableView分组的selectioncolor_Objective C - Fatal编程技术网

Objective c 更改UITableView分组的selectioncolor

Objective c 更改UITableView分组的selectioncolor,objective-c,Objective C,目前,我正在尝试使用以下代码更改分组UITableViewCell(非子类)的背景选择颜色: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... cell.selectionStyle = UITableViewCellSelectionStyleNone; } - (void)tableView:(UITab

目前,我正在尝试使用以下代码更改分组UITableViewCell(非子类)的背景选择颜色:

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

    ...
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];


     cell.contentView.backgroundColor = [UIColor yellowColor];    
}
出现以下问题:

还尝试:

cell.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width - 17, cell.frame.size.height-3)];
        cell.selectedBackgroundView.backgroundColor = coolBlue;
        UIBezierPath *rounded;

            rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(8.0f, 8.0f)];
        else
            rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8.0f, 8.0f)];

        CAShapeLayer *shape = [[CAShapeLayer alloc] init];
        [shape setPath:rounded.CGPath];

        cell.selectedBackgroundView.layer.mask = shape;

当我尝试使用上面的代码时,当我尝试从高度中减去3时,单元格底部的部分被切断。我正在减去3个像素以保持分隔线。

您是否尝试过使用:

[cell setBackgroundColor:[UIColor yellowColor]];

这似乎对我有用,但我的tableView设置可能与您的不同。

非常感谢!!我已经尝试了两周了!