Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing tintColor for button's PDF vector image

I've added a PDF image as an asset to Xcode, I want to change the tintColor of the image but without any success.

I've tried to add User Defined Runtime Attributes, but it won't work.

Also tried to change programatically, but it won't work.

self.buttonBringFriend.imageView.tintColor = UIColor.white

Does anyone have a solution?

Xcode 11.1 Swift 5.1

like image 622
ytpm Avatar asked Oct 20 '25 03:10

ytpm


1 Answers

To set image color, use the below method:

extension UIImageView {

    func setImageColor(color: UIColor) {
            let templateImage = self.image?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
            self.image = templateImage
            self.tintColor = color
        }

    }

How to use:-

self.buttonBringFriend.imageView.setImageColor(color: .white)
like image 197
pkc456 Avatar answered Oct 21 '25 20:10

pkc456



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!