如何更改“聚焦”的 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/