27

Possible Duplicate:
How to Rotate a UIImage 90 degrees?

How to programmatically rotate image by 90 Degrees in iPhone?

Community
  • 1
  • 1
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216

3 Answers3

75
//create rect
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_image.png"]];

//set point of rotation
myImageView.center = CGPointMake(100.0, 100.0);

//rotate rect
myImageView.transform = CGAffineTransformMakeRotation(M_PI_2); //rotation in radians
FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82
Sabobin
  • 4,256
  • 4
  • 27
  • 33
  • Almost perfect answer. Just that you gave rotation by 180 degrees and I wanted by 90 degrees but apart from that it is exactly what I needed. Thanks a lot. :) – Parth Bhatt Apr 08 '11 at 05:04
  • 13
    Use `M_PI` instead of `3.14159265`, and `M_PI_2` instead of `M_PI/2` – Matoe Aug 28 '12 at 02:01
5

see this:

Rotate image in Quartz? Image is upside down! (iPhone)

 myImage.center = CGPointMake(0, 0);
 myImage.transform = CGAffineTransformMakeRotation([degreesToRadians:imageRotationFix]);
Community
  • 1
  • 1
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83
4

this code will rotate the button..

UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(100, 100, 200, 44)];
btn.transform=CGAffineTransformMakeRotation(M_PI / -4);
[btn setTitle:@"RakeshBhatt" forState:UIControlStateNormal];
[self.view addSubview:btn];

same way u can rotate imageview.

Rakesh Bhatt
  • 4,606
  • 3
  • 25
  • 38