开发者

Replace image with any other image when user tap on any image in IPhone

I am creating a application to learn IPhone application development. It will look like http://i52.tinypic.com/2ah8k7o.png that. Now i want when user tap on any image then the tapped image will replace by any other image. How c开发者_Python百科an i do that.

I am just drag and dropping the images and labels from library to xib file. Is it correct way to draw that look or should i use any other way to draw that look and feel.


You should place your images into UIImageView. After this check user taps and simply change image property in UIImageView to new image.

Code like this (in your viewController, for example)

-(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];
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜