Rendering mode set to Template for vector pdf in i

2019-04-25 05:53发布

问题:

I have migrated all my image files to the asset catalogue. All of them are pdf vectors of size 1x. They are set to render as a Template. They show up fine everywhere in size and in color. But there is this one custom TableView Cell from a xib that I has 6 UIImageView s linking to 6 of these images from the catalogue. Somehow they don't respect the tint color, neither default nor custom. Tried changing them programmatically but didn't work either. These same images show up fine in another tableview with static cells inside the main storyboard. I am not able to isolate the issue. Interestingly, the tint shows up perfectly fine once the cell is selected and the selection is changed. Then it tends to show the tint as set in IB. Seems to be like a bug to me in xcode. The problem exists in both, simulator and device. Any help?

PS: Already searched StackOverflow and the answers are all to change the rendering mode to template, which it is that way already.

Image Catalogue

Storyboard

Image before selection

image after selection

回答1:

Template image is work for something like UIButton.image but not UIImageView.image .

You have to set UIImage AlwaysTemplate by yourself.

imageView.image = [[UIImage imageNamed:@"image"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

And set rendering mode in imageAssets is not working in iOS 7.



回答2:

For some reason the initWithStyle method was not being called on the custom cells subclass. So I had to write the initialization code in awakeFromNib. The documentation for UITableView's dequeReuseableCell method clearly mentions that initWithStyle will be called even for custom cells, but it wasn't.