Rendering mode set to Template for vector pdf in image catalogue, but UIImageView wont tint the image in a custom cell
Asked Answered
H

2

8

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

Image Catalogue

Storyboard

Storyboard

Image before selection

enter image description here

image after selection

enter image description here

Hetti answered 18/3, 2015 at 6:17 Comment(0)
G
15

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.

Gilbertegilbertian answered 6/4, 2015 at 5:47 Comment(3)
That worked! Surprisingly its doesn't seem to be mentioned in the documentation.Hetti
Whats more, I wrote it as an initialization code for the custom class of the cell in initWithStyle and it didn't work! I had to write it in 'awakeFromNib'. The documentation for dequeReuseableCell mentions that if a nib is registered it will try and make a cell by calling initWithStyle method of the class. clearly, that is not happening!Hetti
I hope you got the 50 point bounty. I forgot to assign it and stackoverflow never sent me an email saying the question is answered.Hetti
H
0

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.

Hetti answered 28/5, 2015 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.