0

Is it possible to make the navigationcontroller title a button? but without a button look to it. I want it to be just text that if you click on it a view/actionsheet pops up from the bottom If so, can you show me programmatically how I would make it a button? Thanks

Airon Zagarella
  • 707
  • 2
  • 11
  • 17

1 Answers1

7

You can set TitleView of navigationItem to set a button as title.

Here is what i tried and got it working:

UIButton*button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(0, 0, 30, 20);
[button setTitle:@"Testing" forState:UIControlStateNormal];
[button addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[[self navigationItem] setTitleView:button];

But if you don't want it to look like a button, you have set the buttonWithType to custom and set its backGroundImage property.

in btnAction have your code to show the pop ups.

iNoob
  • 3,364
  • 2
  • 26
  • 33
  • Thanks! last thing, im not able to get it to have a clear background. setting backgrouncolor as button.backgroundcolor=[UIcolor clearColor]; does nothing. Have any ideas? – Airon Zagarella Apr 19 '12 at 04:05
  • 1
    @AironZagarella Yes, that won't help, the `backgroundColor` property can be seen only on the edges of the button. So if you don't want the title not to look like button, use `UIButton*button=[UIButton buttonWithType:UIButtonCustom];` that will have clear background. If you want to add your own image you can set the `backgroundImage` property. – iNoob Apr 19 '12 at 04:10
  • typo error i meant: if you don't want the title to look like a button – iNoob Apr 19 '12 at 08:44