它可能会让你感到困惑。您不要将此代码分配给按钮。该代码创建了一个类型为UIBarButtonSystemItemFixedSpace
的按钮。所以,做一下你所说的答案吧。创建固定的& flexible UIBarButtonItem
s(以及其他按钮),然后将其设置在导航栏上。在这种情况下,他们将出现在您的导航栏的左上角区域(通过leftBarButtonItems
):
// Create "Normal" buttons items:
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStylePlain target:Nil action:nil];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithTitle:@"2" style:UIBarButtonItemStylePlain target:Nil action:nil];
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithTitle:@"3" style:UIBarButtonItemStylePlain target:Nil action:nil];
// Create "Spacer" bar button items
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = 20.0f; // or whatever you want
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.navigationItem.leftBarButtonItems = @[button1, fixedItem, button2, flexibleItem, button3];
此外,如果你有一个工具栏,你可以使用工具栏的items
属性:
self.toolbar.items = @[button1, fixedItem, button2, flexibleItem, button3];
的间距现在与按钮,但是现在的按键间隔,他们不再与特定选择的操作工作。这些按钮在之前被创建为UIButton,然后作为UIBarButtonItems放置在导航栏数组中,这是他们之前能够运行的。你认为我如何回到功能? – Camerz007
我们得到它的工作!非常感谢!!我们必须改变目标为“自我”。 – Camerz007
如果这回答了您的问题,请打勾! – Aaron