Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create info button on uinavigationbar on iphone

I've seen many of applications that have an info button (the letter "i" with a circle around it) on the uinavigationbar. How do I add this type of button?

like image 815
Atma Avatar asked Sep 21 '09 18:09

Atma


2 Answers

The previous answer was close, didn't quite compile. Here's what you really want:

// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
like image 56
Blake Watters Avatar answered Sep 23 '22 18:09

Blake Watters


There is memory leak in the answer above. You should use "autorelease" to avoid it. I have tried to edit the answer but I wasn't successful so far.

// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];

THIS IS THE CORRECT WAY TO DO IT.

like image 44
George Asda Avatar answered Sep 23 '22 18:09

George Asda