How do you change the font color of a "focused" UITableView cell? I currently have this....
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
if (context.nextFocusedView) {
CategoryCell *cell = [self.categoryTableView dequeueReusableCellWithIdentifier:@"CategoryCell"];
[cell.categoryLbl setTextColor:[UIColor orangeColor]];
}
}
I know that if you want to change a background of a focused UITableViewCell it would be:
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator {
[context.nextFocusedView setBackgroundColor:[UIColor clearColor]];
[context.previouslyFocusedView setBackgroundColor:[UIColor orangeColor]];
}
In TVOS
UITableViewDelegate
have new method tableView:didUpdateFocusInContext:withAnimationCoordinator:
which will be called when focus change, you can get previous IndexPath and nextFocusIndexPath and then you can use tableView methods to get cells, your code should look like this
- (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];
}
}
Please visit this Apple docs for more detail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With