Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Image rotates on button press

Tags:

ios

I am downloading some images from an API to my ios app and then displaying the images as a button background. Here's the code:

NSData *imageData = [r responseData]; 
UIImage *image =  [UIImage imageWithData:imageData];               
UIBlockButton *imageView = [UIBlockButton buttonWithType:UIButtonTypeCustom];       
[imageView setBackgroundImage:image forState:UIControlStateNormal];

Here's the weird part. Vertical images (Length is less than height) will rotate 90 degrees when I press the button. Has anyone experienced this before/is it a bug?

Edit: So my server sends the images in the rotated state. Somehow the UIButton knows to rotate it when it is not selected, but doesn't make the same correction when I select it.

like image 832
Josh Wilson Avatar asked Sep 02 '11 20:09

Josh Wilson


1 Answers

Add [imageView setBackgroundImage:image forState:UIControlStateHighlighted];

Unless, of course, you prefer another image for the highlighted state to simulate the actual pressing of the button. In that case you will use the other Image in/instead of "image".

But you should get rid of that strange effect at least.

like image 144
Hermann Klecker Avatar answered Nov 20 '22 03:11

Hermann Klecker