我在导航栏中添加了两个按钮,它们工作正常,但我想要它们之间的空间它们都合并了我想要它们之间有点空间
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];
答案 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];