I'm using Xcode 6.0.1 with Swift. I have a UIImage, and I would like to make another image using the old image as a source, with the new image being rotated in some way... say flipped vertically.
This question was already answered a few months ago. However, that solution doesn't work for me, even though the situation is identical.
When I have
var image = UIImage(CGImage: otherImage.CGImage, scale: 1.0, orientation: .DownMirrored)
Xcode complains that there's an "Extra argument 'scale' in call". After checking with the Apple documentation, this makes no sense, as that version of the initializer does take those three arguments. Leaving out the scale and orientation arguments does fix the problem, but prevents me from doing the rotation.
The only other reference to this that I can find is this guy, who had the same problem.
What do you think?
I do need this to run on this version of Xcode, so if there's an alternate way to perform the rotation (I haven't found one yet) that would be useful.
You can use it like this:
With flipped flag specified:
Swift 5 Solution
Here is the simplest solution
and to use this solution you can do the following
Here is a simple extension to UIImage:
(Source)
Use it with:
The former will rotate an image and flip it if flip is set to true.
Try this code, it worked for me:
@confile answer updated to Swift 4