更改UITableView单元附件tvOS中SFSymbol的色调

问题描述 投票:0回答:1

我将附件视图添加到具有以下内容的单元格中:

UIImageSymbolConfiguration* configuration = [UIImageSymbolConfiguration configurationWithPointSize:28 weight:UIImageSymbolWeightRegular];
UIImageView* accessoryView = [[[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"globe" withConfiguration:configuration]] autorelease];

[accessoryView setImage:[imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[accessoryView setTintColor:[UIColor labelColor]];

[cell setAccessoryView: accessoryView];

此方法有效,但如何配置它,以便在突出显示单元格时,地球图标从labelColor色变为黑色(因此与文本颜色匹配)?

我也尝试制作突出显示的图像,但是没有任何效果:

UIImageSymbolConfiguration* configuration = [UIImageSymbolConfiguration configurationWithPointSize:28 weight:UIImageSymbolWeightRegular];
UIImageView* accessoryView = [[[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"globe" withConfiguration:configuration]] autorelease];

UIImage* normalImage = [accessoryView.image imageWithTintColor:[UIColor labelColor]];
UIImage* highlightImage = [accessoryView.image imageWithTintColor:[UIColor blackColor]];

[accessoryView setImage:normalImage];
[accessoryView setHighlightedImage:highlightImage];

[cell setAccessoryView:accessoryView];

此外,突出显示的图像似乎根本没有使用过:

UIImage* image = [[UIImage systemImageNamed:@"checkmark" withConfiguration:configuration] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImage* highlightedImage = [[UIImage systemImageNamed:@"globe" withConfiguration:configuration] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

UIImageView* accessoryView = [[[UIImageView alloc] initWithImage:image highlightedImage:highlightedImage] autorelease];
[cell setAccessoryView:accessoryView];

在上面的代码中,突出显示的图像从不显示。

cocoa uiimageview uiimage highlight tvos
1个回答
0
投票

这似乎起作用:

-(void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
    NSIndexPath* nextPath = [context nextFocusedIndexPath];
    if (nextPath)
    {
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:nextPath];
        UIImageView* accessoryView = (UIImageView *)[cell accessoryView];
        [accessoryView setTintColor:[UIColor blackColor]];
    }

    NSIndexPath* prevPath = [context previouslyFocusedIndexPath];
    if (prevPath)
    {
        UITableViewCell* cell = [tableView cellForRowAtIndexPath:prevPath];
        UIImageView* accessoryView = (UIImageView *)[cell accessoryView];
        [accessoryView setTintColor:[UIColor labelColor]];
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.