如何在导航栏中添加两个带有一些空格的按钮

时间:2013-02-28 05:51:05

标签: ipad uibutton uinavigationbar

我在导航栏中添加了两个按钮,它们工作正常,但我想要它们之间的空间它们都合并了我想要它们之间有点空间

  UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] initWithTitle:@"Add"
                                                           style:UIBarButtonItemStylePlain
                                                          target:self
                                                          action:@selector(Add)];

UIBarButtonItem *btnEdit = [[UIBarButtonItem alloc] initWithTitle:@"Add"
                                                           style:UIBarButtonItemStylePlain
                                                          target:self
                                                          action:@selector(Add)];


UIToolbar *rightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
rightToolBar.backgroundColor = [UIColor clearColor];
rightToolBar.tintColor = [UIColor colorWithRed:40.0/255.0 green:48.0/255.0 blue:51.0/255.0 alpha:0.0];
NSArray *buttonsRight = [NSArray arrayWithObjects:btnEdit, btnAdd, nil];
[rightToolBar setItems:buttonsRight];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightToolBar];     

1 个答案:

答案 0 :(得分:1)

您可以在UIBarButtonItem

之间添加这两者中的任何一个
UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]

UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]

请注意,要设置固定空间UIBarButtonItem的宽度,您需要设置.width属性

[fixed setWidth:455.0f];