Search code examples
iosuiimageuiimageorientation

How to flip UIImage horizontally?


How to flip the UIImage horizontally, I found UIImageOrientationUpMirrored enumeration value in the UIImage class reference, how to make use of this property to flip UIImage.


Solution

  • Objective-C

    UIImage* sourceImage = [UIImage imageNamed:@"whatever.png"];
    
    UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage 
                                                scale:sourceImage.scale
                                          orientation:UIImageOrientationUpMirrored];
    

    Swift

    let flippedImage = myImage.withHorizontallyFlippedOrientation()