3

img1

As you can see on the image above, these two svg images are losing their quality a bit. In Assets's Attributes inscpector, their Scale property is set to Single Scale.
Those are button's imageViews, resized to fill the button:

button.setImage(UIImage(named: img1.rawValue), for: .normal) 
button.contentHorizontalAlignment = .fill
button.contentVerticalAlignment = .fill
button.imageView?.contentMode = .scaleAspectFit
stackich
  • 3,607
  • 3
  • 17
  • 41

1 Answers1

2

I'm using this piece of code for resizing images to the desired size without losing quality

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