views:

1485

answers:

2

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?

A: 

You should be able to add an "Info Light" type button to the navigationItem of the view controller that the UINavigationController is currently displaying. Something like this could go in your view controller code:

- (void) viewDidLoad {
  UIButton * info = [UIButton buttonWithType:UIButtonTypeInfoLight];
  // set your button's target and selector for whatever action here.
  self.navigationItem.rightBarButtonItem.customView = info;
}
Kevlar
Kevlar, Please modify your answer.. buttonType is a readonly property. You can't set it!
Prakash
my bad, i was going from memory and didnt have the docs in front of me; changing now.
Kevlar
+9  A: 

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