如何将按钮添加到导航控制器的中心我已经尝试了下面的代码
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[titleButton setFrame:CGRectMake(0, 0, 200, 35)]; self.navigationItem.titleView = titleButton;
但是屏幕显示空白按钮没有颜色如何正常显示
如何将按钮添加到导航控制器的中心我已经尝试了下面的代码
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[titleButton setFrame:CGRectMake(0, 0, 200, 35)]; self.navigationItem.titleView = titleButton;
但是屏幕显示空白按钮没有颜色如何正常显示
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[titleButton setFrame:CGRectMake((self.view.frame.size.width - 200)/2, 3, 200, 35)];
[self.navigationController.navigationBar addSubview:titleButton];
我用它和我的代码工作正常
UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[titleButton setTitle:@"Title" forState:UIControlStateNormal];
[titleButton setFrame:CGRectMake(0, 0, 200, 35)];
self.navigationItem.titleView = titleButton;
试试看。