我正在从 API 下载一些图像到我的 ios 应用程序,然后将图像显示为按钮背景。这是代码:
NSData *imageData = [r responseData];
UIImage *image = [UIImage imageWithData:imageData];
UIBlockButton *imageView = [UIBlockButton buttonWithType:UIButtonTypeCustom];
[imageView setBackgroundImage:image forState:UIControlStateNormal];
这是奇怪的部分。当我按下按钮时,垂直图像(长度小于高度)将旋转 90 度。有没有人以前遇到过这个/这是一个错误吗?
编辑:所以我的服务器以旋转状态发送图像。 UIButton 以某种方式知道在未选中时旋转它,但在我选中它时不会进行相同的更正。
最佳答案
添加[imageView setBackgroundImage:image forState:UIControlStateHighlighted];
当然,除非您更喜欢高亮状态下的另一个图像来模拟按钮的实际按下。在这种情况下,您将在/而不是“图像”中使用其他图像。
但是你至少应该摆脱那个奇怪的效果。
关于iOS图像在按下按钮时旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7289046/