Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Images in UITableView cells are not honoring tintColor

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

enter image description here

like image 498
RobertJoseph Avatar asked Sep 15 '14 13:09

RobertJoseph


4 Answers

Every UIImageView has the property tintColor on iOS7+

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

like image 162
dopcn Avatar answered Nov 10 '22 20:11

dopcn


The below setup worked for me well.

In the storyboard, set cell's contentView tintColor as your desired color and UIImagview's tintColor as default.

like image 28
john raja Avatar answered Oct 12 '22 12:10

john raja


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.

like image 9
Sean Avatar answered Nov 10 '22 20:11

Sean


Here is an example:

UIImage *image = [[UIImage imageNamed:@"ic_email_white"]
                  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[[cell imageView] setImage:image];
[[cell imageView] setTintColor:[UIColor redColor]];
like image 2
meda Avatar answered Nov 10 '22 20:11

meda