Images in UITableView cells are not honoring tintC

2019-04-21 20:49发布

问题:

I have a UITableView which is comprised of static cells. In IB I've set each UITableViewCell's style to "Basic" and set an image (see screenshot). The buttons in my nav bar honor the tintColor property but the images in the tableview do not. Thus far I've done everything in IB - do I have to use code if I want the images to honor the tintColor property too?

Thanks

回答1:

Every UIImageView has the property tintColor on iOS7+

Try to set cell's imageView.image.renderingMode to UIImageRenderingModeAlwaysTemplate in storyboard User Defined Runtime Attributes



回答2:

What a headache this problem is after so many versions! The only thing that is a sure fire fix, assuming everything is "right" (template image, etc) is subclassing the UIImageView and overriding didMoveToSuperview with this...

- (void)didMoveToSuperview
{
    [self setHighlighted:YES];
    [self setHighlighted:NO];
    [super didMoveToSuperview];
}

It's a hack but it works.



回答3:

Here is an example:

UIImage *image = [[UIImage imageNamed:@"ic_email_white"]
                  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[[cell imageView] setImage:image];
[[cell imageView] setTintColor:[UIColor redColor]];