Reputation: 1
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
Upvotes: 0
Views: 606
Reputation: 2002
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[titleButton setFrame:CGRectMake((self.view.frame.size.width - 200)/2, 3, 200, 35)];
[self.navigationController.navigationBar addSubview:titleButton];
Upvotes: 1
Reputation: 1098
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.
Upvotes: 0