IOS image rotates when a button is pressed

I upload some images from the API to my ios app and then display the images as the button background. Here is 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 shorter than height) will rotate 90 degrees when I press the button. Has anyone experienced this before / is this a bug?

Edit: my server sends images in a rotating state. Somehow UIButton knows to rotate it when it is not selected, but does not perform the same correction when I select it.

+6
source share
1 answer

Add [imageView setBackgroundImage:image forState:UIControlStateHighlighted];

Unless, of course, you prefer a different image for the selected state to simulate the actual click of a button. In this case, you will use a different image in / instead of the "image".

But you must get rid of this strange effect.

+3
source

Source: https://habr.com/ru/post/896522/


All Articles