我如何添加左边的barButton
或旁边的按钮rightbarButton
, 我的意思是我需要在标题栏上有2个以上的按钮是可能的吗?如何添加左边的酒吧控制器或右边的酒吧控制器旁边的按钮
thanx提前
我如何添加左边的barButton
或旁边的按钮rightbarButton
, 我的意思是我需要在标题栏上有2个以上的按钮是可能的吗?如何添加左边的酒吧控制器或右边的酒吧控制器旁边的按钮
thanx提前
由于从this blog post得出:
认为一个工具栏为您的容器,而不是 的UIView的对象。由于UIToolBar基于UIView,因此可以使用上述技巧将 添加到导航栏右侧的 。该 下面的代码演示了如何添加 两个标准按键向右 侧:
// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
同时检查SO发布
您可以使用视图具有两个按钮在你左边巴顿 -
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftBtnsView];
我建议使用UISegmentedControl
来保存所有按钮,并使用 [[UIButton alloc] initWithCustomView:]
来显示段控制。
下面是你如何去做这件事的一个例子。我使用的是随此示例的顶部导航栏MasterDetailView
模板:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] init];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] init];
leftButton.title = @"Left button";
rightButton.title = @"right button";
self.navigationItem.leftBarButtonItem = leftButton;
self.navigationItem.rightBarButtonItem = rightButton;
}
你可以做这样的事情,有一些所谓的UINavigationItem.rightBarButtonItems
的UIBarButtonItem * settingsButton = [[的UIBarButtonItem [] UIImageNameName:@“xxx.png”] style:UIBarButtonItemStyleDone target:self action:@selector(something)];
的UIBarButtonItem *菜单按钮= [[ALLOC的UIBarButtonItem] initWithImage:[UIImage的imageNamed:@ “xxx.png”] 样式:UIBarButtonItemStyleDone目标:自 动作:@selector(东西)];
self.navigationItem.rightBarButtonItems = @ [settingsButton,menuButton];
我认为你需要像这样
UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithTitle:@"First" style:UIBarButtonItemStyleBordered target:self action:nil];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStyleBordered target:self action:nil];
[email protected][firstButton, secondButton];
它将在左侧导航栏中的添加两个栏按钮的项目。你可以用同样的方式使它在右侧
[email protected][firstButton, secondButton];
这不是问题 – artud2000 2014-02-04 20:40:54