0

如何将按钮添加到导航控制器的中心我已经尝试了下面的代码

UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

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

self.navigationItem.titleView = titleButton;

但是屏幕显示空白按钮没有颜色如何正常显示

4

2 回答 2

1
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

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

[self.navigationController.navigationBar addSubview:titleButton];
于 2012-12-27T13:29:33.053 回答
0

我用它和我的代码工作正常

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

self.navigationItem.titleView = titleButton;

试试看。

于 2012-12-27T13:28:33.547 回答