1

我只在左侧或右侧添加 UIBarbuttonitem。现在我想在 uinavigationbar 的中心添加 UIbarbuttonitem。我怎样才能做到这一点?非常感谢

4

2 回答 2

2

尝试这个:

 UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [titleButton setFrame:CGRectMake(0, 0, 170, 35)];
 self.navigationItem.titleView =  [[UIBarButtonItem alloc] initWithCustomView:titleButton];
于 2013-08-09T15:56:15.690 回答
1

您可以像这样添加另一个 UIBarButtonItem 作为“间隔”:

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(buttonTapped)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spacer.width = 125.0f;

[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:spacer, barButton, nil]];
于 2013-08-09T15:40:19.743 回答