iPhone:突出显示的图像无法与 initWithImage 一起使用

标签 iphone

我希望在单击 UIImageView 时显示突出显示的图像。我遇到了突出显示的图像并尝试了如下所示。

myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"] highlightedImage:[UIImage imageNamed:@"1_highlighted.png"]];

但是,突出显示的图像根本不起作用。当我单击 UIImageView (1.png) 时,它不显示突出显示的图像 (1_highlighted.png)。

有人可以指导我该怎么做吗?

谢谢!

最佳答案

单击 ImageView 不会将其设置为突出显示的图像。默认情况下, ImageView 没有用户交互。

如果您想要此操作,您需要在 ImageView 上启用用户交互并向其添加操作。

您可以通过在代码中设置突出显示状态来在两个图像之间切换:

imageView.highlighted = YES;

关于iPhone:突出显示的图像无法与 initWithImage 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8306729/

相关文章:

iphone - 使用Newtonsoft.Json消除引号转义

iphone - 有没有办法设置 iPhone 模拟器中的可用内存量?

ios - 我的 iPhone 3G 无法从 Xcode5 中选择为目标。这可以修复吗?

iphone - 默认 UIPickerView 高度

iphone - 将数组的内容写入文本文件

iphone - SQLite-时间戳

iphone - Opengl 中的重复状态更改

iphone - 我可以淡化/动画 UIToolbar 的 tintColor 吗?

iphone - 对于 "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted."该怎么办

iphone - 如何制作 iPhone 应用程序 "skinnable"?