views:

53

answers:

2

I have 5 round buttons in a row, each one, 40x40 pixels. Between each one, I have 20 pixels.

40x40 pixels is too small to touch, but as I have 20 pixels of space between each button I can extend the button touch area to 60x60 pixels, making it easy to touch. I could simply using the dirty solution of creating a square 60x60 pixels transparent image, put this over the button and make this touchable, but I know it is possible to extend a button touch area by creating a custom class and changing a parameter.

I know this is possible because I saw this done before (but I cannot find the URL). I know it is something related to hitTest.

How can this be done? Thanks.

A: 

You can always make its frame bigger, i.e. yourButton.frame = CGMRectMake(0,0,60,60); I usually do this when adding one of the info buttons.

Eiko
+1  A: 

Eiko is absolutely right. Here's some simple code you can use that is independent of the button's location that somebody gave me for expanding the Info button frame.

CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x - 25, 
                                          infoButton.frame.origin.y - 25, 
                                          infoButton.frame.size.width + 50, 
                                          infoButton.frame.size.height + 50);
    [infoButton setFrame:newInfoButtonRect];

You might want to watch out if you're using a background image as opposed to an image ( button setBackgroundImage: vs button setImage: forState:) because a background image will stretch with the frame while a normal image will not.

Luke
thanks!!!!!!!!!!!!
Digital Robot