Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate UIImage

I'm developing an iOS app for iPad. Is there any way to rotate a UIImage 90º and then add it to a UIImageView? I've tried a lot of different codes but none worked...

Thanks!

like image 735
Marti Serra Vivancos Avatar asked Feb 13 '13 16:02

Marti Serra Vivancos


People also ask

How do you rotate UIImage in Objective C?

You may rotate UIImageView itself with: UIImageView *iv = [[UIImageView alloc] initWithImage:image]; iv. transform = CGAffineTransformMakeRotation(M_PI_2); Or if you really want to change image, you may use code from this answer, it works.

How do I rotate UIImageView?

Step 1 − Open Xcode→SingleViewApplication→name it RotateImage. Step 2 − Open Main. storyboard, add UIImageView and add 2 buttons as shown below name them ROTATE BY 90 DEGREES AND ROTATE BY 45 DEGREES. Add some sample images to UIImage View.

How do I rotate an image in Swift?

Go to the ViewController. swift file and implement the rotateImage method. The image will rotate 180 degrees using the CGAffineTranform function. Build and Run the project and tap the Rotate Button to rotate the image.


1 Answers

You may rotate UIImageView itself with:

UIImageView *iv = [[UIImageView alloc] initWithImage:image];
iv.transform = CGAffineTransformMakeRotation(M_PI_2);

Or if you really want to change image, you may use code from this answer, it works.

like image 189
kovpas Avatar answered Oct 01 '22 13:10

kovpas