tableview,改变焦点tvos的字体颜色

Jen*_*ers 4 objective-c uitableview tvos

如何更改"聚焦"UITableView单元格的字体颜色?我现在有这个....

 - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
if (context.nextFocusedView) {
    CategoryCell *cell = [self.categoryTableView dequeueReusableCellWithIdentifier:@"CategoryCell"];
    [cell.categoryLbl setTextColor:[UIColor orangeColor]];
     }
 }
Run Code Online (Sandbox Code Playgroud)

我知道如果你想改变一个专注的UITableViewCell的背景,它将是:

   - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
    [context.nextFocusedView setBackgroundColor:[UIColor clearColor]];
[context.previouslyFocusedView setBackgroundColor:[UIColor orangeColor]];
 }
Run Code Online (Sandbox Code Playgroud)

Adn*_*tab 9

在焦点更改时将调用TVOS UITableViewDelegate新方法tableView:didUpdateFocusInContext:withAnimationCoordinator:,您可以获取以前的IndexPath和nextFocusIndexPath,然后您可以使用tableView方法获取单元格,您的代码应该如下所示

- (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
    NSIndexPath *prevIndexPath = [context previouslyFocusedIndexPath];
    if (prevIndexPath)
    {
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:prevIndexPath];
        cell.textLabel.textColor = [UIColor white];
    }
    NSIndexPath *nextIndexPath = [context nextFocusedIndexPath];
    if (nextIndexPath)
    {
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nextIndexPath];
    cell.textLabel.textColor = [UIColor blackColor];
    } 
}
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请访问此Apple文档