How to flip UIImage horizontally with Swift?

后端 未结 9 1886
余生分开走
余生分开走 2020-12-13 00:16

The solution to do UIImage flipping is with the Objective-C code:

[UIImage imageWithCGImage:img.CGImage scale:1.0 orientation: UIImageOrientationDownMirrored         


        
9条回答
  •  粉色の甜心
    2020-12-13 01:04

    For me the simplest way was to use the .withHorizontallyFlippedOrientation() instance method of UIImage as follows:

    let flippedImage = straightImage.withHorizontallyFlippedOrientation()

    Simple one-liners always make me happy :)

提交回复
热议问题