Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tint color on pdf asset in Xcode?

I created a new image set, set "Scales" as "Single Scale" and placed my PDF asset in. Afterwards, I set "Render as" to "Template Image" and when I set a UIImageView to display my asset, it shows up but I cannot change the tint color in storyboard. Does anyone know what I need to do in order to be able to modify the tint color on a PDF vector asset in Xcode?

like image 753
Eman Harout Avatar asked Dec 14 '22 23:12

Eman Harout


1 Answers

Setting the UIImageView's image in code doesn't produce this problem.

There is a bug in Xcode which prevents UIImageView from coloring its template image in tint color when loaded from Interface Builder. See: rdar://18448072

If you don't want to set the image in code, the most elegant solution I found was creating the following extension for UIImageView:

import UIKit

extension UIImageView {
    override public func awakeFromNib() {
        super.awakeFromNib()
        tintColorDidChange()
    }
}

Props to this gist.

like image 118
Nikita Kukushkin Avatar answered Jan 01 '23 14:01

Nikita Kukushkin