Extension

UIImage

This extension adds a convenient resizing method to UIImage.

Declaration

extension UIImage

Overview

This extension adds a function to UIImage that returns copy of the image sized to the specification.

Topics

Resizing

This function makes a copy of an image resized to fit a specified CGSize.

resized(…)

func resized(to size: CGSize) -> UIImage {
    let rect = CGRect(origin: .zero, size: size)
    let vertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height)
    return UIGraphicsImageRenderer(size: size).image { _ in
        let ctx = UIGraphicsGetCurrentContext()
        ctx?.saveGState()
        ctx?.concatenate(vertical)
        draw(in: rect)
        ctx?.restoreGState()
        UIGraphicsEndImageContext()
    }
}
background Made with Flow.
underscore Made with Flow.
line2 Made with Flow.
line1 Made with Flow.
circle Made with Flow.
hit Made with Flow.

result(s) found for “”.