[英]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.我已将
PDF
图像作为资产添加到Xcode
,我想更改图像的tintColor
但没有任何成功。
I've tried to add User Defined Runtime Attributes
, but it won't work.我尝试添加
User Defined Runtime Attributes
,但它不起作用。
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 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您是否在资产属性中设置了
Render As: Template Image
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.