Search code examples
iosxcodepdfuiimageviewassets

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?


Solution

  • 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.