开发者

iphone - how to extend a button touch area?

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 开发者_StackOverflow中文版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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜