简体   繁体   中英

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

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)

Have you set Render As: Template Image in the Asset properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM