How does one apply UIEdgeInsets (or some variation thereof) to a CGImage? This is what I'm ultimately trying to achieve but the CGImage is not recognizing the bottom inset applied to the UIImage before it is converted to a CGImage.
var image = someUIImage
image = image.withAlignmentRectInsets(UIEdgeInsets(top: 0, left: 0, bottom: (image.size.height / 2), right: 0))
let imageCG: CGImage = image.cgImage!
layer.contents = imageCG
And I can't apply an inset to the CGImage directly (as seen here).
let image = someUIImage.cgImage!
image. // can't apply any inset here
layer.contents = image
Workaround?
Try this way :
let resizable = img.resizableImage(withCapInsets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8), resizingMode: .stretch)