How to flip UIImage horizontally with Swift?

后端 未结 9 1883
余生分开走
余生分开走 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 00:43

    Most factory methods are converted to initializers in swift. Whenever available, even if the class method is still available, they are preferred. You can use:

        init(CGImage cgImage: CGImage!, scale: CGFloat, orientation: UIImageOrientation)
    

    The usage would look like this:

    var image = UIImage(CGImage: img.CGImage, scale: 1.0, orientation: .DownMirrored)
    

提交回复
热议问题