objective-c - tableview,更改焦点 tvos 的字体颜色

标签 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]];
     }
 }

我知道如果你想改变一个聚焦的 UITableViewCell 的背景,它会是:

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

最佳答案

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];
    } 
}

请访问此Apple docs更多详情

关于objective-c - tableview,更改焦点 tvos 的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32917328/

相关文章:

ios - iOS Objective-C阻止警告:控件到达非空函数的末尾

objective-c - 如何在iOS7风格上实现 `viewForHeaderInSection`?

iOS:如何从 tableview 的自定义单元格中的 UITextField 访问值

ios - 如何在不以编程方式更改其他单元格的情况下将 UIButton 样式设置为特定的 UITableViewCell?

tvos - 如何处理 tvOS MenuBarTemplate 选择?

objective-c - 无效的 Swift 支持/SwiftSupport 文件夹为空

ios - 如何从 View 中获取所有按钮?

ios - UIWebView 加载第一个 HTTPS 页面正常,但在打开链接时失败

swift - 如何在 Swift 中检测 Apple TV 上的按钮突出显示

ios - 图像资源无效