Monday, June 29, 2009

Iphone InfoButton Tip

The Apple utilityApp template in both OS versions 2.2 and 3.0 has an infoButton. When this button is tapped, the user is presented with a new view, usually for preferences, or setting up the application. This transition does a "flip" transition between the 2 views that is pretty nice, really. The button when hit "glows" and looks great.

There is a Problem however. The damn button is hard to hit. Usually it takes a bunch of taps just select it. The info button as it is in the template is created in a nib. You can edit the xib file with Interface Builder, however you can only change its position, and not size. Since the infoButton is just a specialized button, you can programatically change its frame size. It is the size of this frame that determines the area that is touch sensitive. That is a bigger frame, the easier it is to press.

To do this first create an outlet for the infoButton in the appropriate view from the template. In OS 3.0 it is called MainView Next bind this outlet to the infoButton using Interface Builder. In your views init code insert the following (I did it in my setupSubViews method):

//Make it so we can hit the dmn thing.

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


This will make the button 50 pixels bigger. Much easier to hit!


Hope this Helps!

Tìoraidh!

2 comments:

  1. Thanks Rick!

    I was wondering how Apple made their info buttons easier to hit. As a 1rst time iPhone developer, it was frustrating to me that my info button was hard to hit.

    Thanks a Million...

    ReplyDelete
  2. Just had the same problem, and your solution just came up great. Saved me much work! Thanks a lot!! (and thanks google ;D)

    ReplyDelete