1

我在导航栏中添加了两个按钮,它们工作正常,但我希望它们之间有空间,它们都结合在一起,我希望它们之间有一点空间

  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];     
4

1 回答 1

1

您可以在您的UIBarButtonItem

UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]

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

请注意,要设置 Fixed Space 的宽度UIBarButtonItem,您需要设置.width属性

[fixed setWidth:455.0f];
于 2013-02-28T06:20:46.603 回答