Question

Is it possible to register a touch of a picture without using UIButton? And if it is, how can i do this?

I can just think of changing the background of a button in the code, and then use IBAction to detect the touch.

Btw, sorry for my english.

Was it helpful?

Solution

Sure. You can put a UITapGestureRecognizer on a UIImageView (remember to set the image view's userInteractionEnabled property to YES):

// assumes "myImageView" is your UIImageView that has user interaction enabled
UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)] autorelease];
[myImageView addGestureRecognizer:tap];

later in your controller...

- (void)tap:(UITapGestureRecognizer *)recognizer 
{
    // whatever you want
}

However, you can set up a UIButton to basically be a dumb image. Just set the background image for the normal state, disable all the adjusting on highlighting and touches, and you should have exactly what you're thinking of.

If I've misunderstood what you're getting at, feel free to clarify.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top