0

how to add button to center of navigationcontroller i have tried the below code

UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

[titleButton setFrame:CGRectMake(0, 0, 200, 35)];

self.navigationItem.titleView = titleButton;

but the screen shows blank button with out colour how to show it normal

Community
  • 1
  • 1
  • Can you be a bit more clear? How exactly do you want the button to look like? No border? White background? Black text? – sooper Dec 27 '12 at 13:54

2 Answers2

1
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

[titleButton setFrame:CGRectMake((self.view.frame.size.width - 200)/2, 3, 200, 35)];

[self.navigationController.navigationBar addSubview:titleButton];
thavasidurai
  • 1,972
  • 1
  • 26
  • 51
0

I used this with my codes working fine

UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[titleButton setTitle:@"Title" forState:UIControlStateNormal];
[titleButton setFrame:CGRectMake(0, 0, 200, 35)];

self.navigationItem.titleView = titleButton;

try it.

spider1983
  • 1,098
  • 1
  • 7
  • 14