【问题标题】:SVG image loses quality when resized调整大小时 SVG 图像质量下降
【发布时间】:2021-11-06 03:42:05
【问题描述】:

如上图所示,这两个svg 图像的质量有所下降。在Assets 的属性检查器中,它们的Scale 属性设置为Single Scale
这些是按钮的图像视图,调整大小以填充按钮:

button.setImage(UIImage(named: img1.rawValue), for: .normal) 
button.contentHorizontalAlignment = .fill
button.contentVerticalAlignment = .fill
button.imageView?.contentMode = .scaleAspectFit

【问题讨论】:

    标签: swift svg uibutton uiimageview uikit


    【解决方案1】:

    我正在使用这段代码将图像调整为所需大小而不会降低质量

    extension UIImage {
        func resize(targetSize: CGSize) -> UIImage {
            return UIGraphicsImageRenderer(size:targetSize).image { _ in
                self.draw(in: CGRect(origin: .zero, size: targetSize))
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2014-02-17
      • 2021-02-15
      相关资源
      最近更新 更多