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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With