我创建了UIToolBar
并设置了两个UIBarButtonItem
,然后将此工具栏分配给self.navigationItem.rightBarButtonItem
。
除了按钮顶部有一条线外,一切都很完美。
代码:
UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithTitle:@"Add"
style:UIBarButtonItemStylePlain
target:self
action:@selector(addNewRow:)];
UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
style:UIBarButtonItemStylePlain
target:self
action:@selector(editRow:)];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
[toolBar setItems:@[addItem, editItem]];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolBar];
请看我的图片:
答案 0 :(得分:2)
你通过摆脱工具栏摆脱了这条线。
UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStylePlain target:self action:@selector(addNewRow:)];
UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(editRow:)];
self.navigationItem.rightBarButtonItems = @[ addItem, editItem ];