Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tableview, change font color of focus tvos

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]];
 }
like image 812
Jenel Ejercito Myers Avatar asked Oct 02 '15 23:10

Jenel Ejercito Myers


1 Answers

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

like image 188
Adnan Aftab Avatar answered Sep 21 '22 20:09

Adnan Aftab