UIScrollView可点击图片iPhone

时间:2010-08-10 15:54:54

标签: iphone image uiscrollview

我在我的应用中创建了一个UIScrollView - 改编自以下示例代码:http://developer.apple.com/iphone/library/samplecode/Scrolling/Introduction/Intro.html

但我不知道如何使图像可点击

有什么建议吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

将它们放在UIButtons上。

答案 1 :(得分:2)

是啊......“把它们放在UIButtons上”

//get the image to use, however you want
UIImage* image = [product.images objectAtIndex:i];

UIButton* button = [[UIButton alloc] init];

//set the button states you want the image to show up for
[button setImage:image forState:UIControlStateNormal];
[button setImage:image forState:UIControlStateHighlighted];

//create the touch event target, i am calling the 'productImagePressed' method
[button addTarget:self action:@selector(productImagePressed:)
forControlEvents:UIControlEventTouchUpInside];
//i set the tag to the image #, i was looking though an array of them
button.tag = i;
//add the new button w/ the image to your scrollview 
[ImagesScroller addSubview:button];
[button release];