user1932166
user1932166

Reputation: 1

adding button to center of navigationcontroller

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

Answers (2)

thavasidurai
thavasidurai

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

spider1983
spider1983

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

Related Questions