我在iOS项目中使用svg图像。我必须将梯度设置为svg图像,但我不知道如何在iOS中给svg图像设置梯度。如果有人早些做过这件事,请帮帮我。
我正在使用这个函数得到不同的彩色图像与svg图像的捆绑。现在我想填充渐变颜色到svg图像。我怎么能做到这一点。为此,我正在使用SVGKit库。
func getImageFromSVG_StaticColor(imgStr:String,colorStr:String) -> UIImage {
let svgURL = Bundle.main.url(forResource: imgStr, withExtension: "svg")
let img_data = try? Data(contentsOf: svgURL!)
let image : SVGKImage = SVGKImage(data: img_data)
image.fillColor(color: UIColor.init(hexString: colorStr, alpha: 1.0), opacity: 1.0)
return image.uiImage
}发布于 2021-12-31 09:23:33
您应该在图像svg上重写UIview类,并在UIview上设置渐变颜色。
let view = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
let gradient = CAGradientLayer()
gradient.frame = view.bounds
gradient.colors = [UIColor.white.cgColor, UIColor.black.cgColor]
view.layer.insertSublayer(gradient, at: 0)https://stackoverflow.com/questions/70516294
复制相似问题