An info button is an easy and straightforward way to provide access to a modal view in your application.

It’s especially useful when you want to display something like an about screen but don’t have a dedicated area for settings.

To add one, simply create a button in the viewDidLoad method of your view controller and add it to the title bar:

UIButton *infoButton = [UIButton buttonWithType:
    UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(showInfo:)
    forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]
    initWithCustomView:infoButton];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
[rightBarButtonItem release];


In the example above I created an info button with a light background and set it as the right bar button item in the title bar of the view controller.

To finish, you just need to define the showInfo method and display a modal view when users tap the button:

– (IBAction)showInfo:(id)sender
{
    if (! self.infoViewController)
    {
        self.infoViewController = [[InfoViewController alloc]             initWithNibName:NSStringFromClass
            ([InfoViewController class]) bundle:nil];
    }

    UINavigationController *infoViewNavController =
        [[UINavigationController alloc]
        initWithRootViewController:self.infoViewController];

    [self.navigationController presentModalViewController:
        infoViewNavController animated:YES];
    [infoViewNavController release];
}


I declared an instance of my modal view (InfoViewController) in the view controller’s header file since the view never changes and doesn’t need to be recreated each time.