【问题标题】:Replace image with any other image when user tap on any image in IPhone当用户点击 iPhone 中的任何图像时,将图像替换为任何其他图像
【发布时间】:2011-08-05 10:34:47
【问题描述】:

我正在创建一个应用程序来学习 iPhone 应用程序开发。它看起来像http://i52.tinypic.com/2ah8k7o.png。现在我想当用户点击任何图像时,点击的图像将被任何其他图像替换。我该怎么做。

我只是将图像和标签从库拖放到 xib 文件。它是绘制那种外观的正确方法还是我应该使用任何其他方式来绘制那种外观和感觉。

【问题讨论】:

标签: iphone xcode xcode4 ios-simulator


【解决方案1】:

您应该将图像放入 UIImageView。在此检查用户点击后,只需将 UIImageView 中的image 属性更改为新图像。

这样的代码(例如在您的 viewController 中)

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UIView *imgView = [[touches anyObject] view];
if ([view isKindOfClass:UIImageView.class]){
    UIImage *newImg = [UIImage imageNamed:@"newImg.png"]; // newImg.png should be in bundle
    [(UIImageView*)view setImage:newImg];
}

}

【讨论】:

    猜你喜欢
    • 2014-12-06
    • 2014-06-09
    • 2016-09-24
    • 1970-01-01
    • 2015-01-25
    • 1970-01-01
    • 2015-02-03
    • 2015-11-03
    • 1970-01-01
    相关资源
    最近更新 更多