UITableView:更改选定的单元格背景颜色

时间:2015-10-02 08:46:04

标签: objective-c tvos

在tvOS上的UITableView导航时,我无法更改白色背景。

为了设计目的,我在整张桌子上编辑了背景/文字颜色,因此选择的白色背景很烦人。

我试过了:

cell.selectedBackgroundView.backgroundColor = [UIColor blackColor];

但它没有更新突出显示的背景颜色。

3 个答案:

答案 0 :(得分:6)

tvOS使用焦点来显示当前所选项目。要更改backgroundColor,请覆盖单元类中的didUpdateFocusInContext()方法。

public override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
    context.previouslyFocusedView?.backgroundColor = UIColor.clearColor()
    context.nextFocusedView?.backgroundColor = UIColor.blackColor()
}

答案 1 :(得分:6)

您只需使用focusStyle:

即可禁用此功能
self.focusStyle = UITableViewCellFocusStyle.Custom

这将禁用白色背景,但也会禁用任何默认缩放动画。您应该使用自定义UITableViewCellFocusStyle自行处理此问题。

答案 2 :(得分:0)

你必须创建一个UIView并将其设置为你的CellForRowAtIndexPath中的backgroundview

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategoryCell" forIndexPath:indexPath];
    UIView *bgColorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 405, 60)];

    bgColorView.backgroundColor = [UIColor blackColor];
    [cell setSelectedBackgroundView:bgColorView];
相关问题