iOS:增加与UIBarButtonItem的间距

时间:2015-08-29 19:35:50

标签: ios swift insets uiedgeinsets

我制作了一个自定义UINavigationBar,如下所示:[1]

现在我想增加左右按钮之间的间距。我尝试以这种方式使用UIEdgeInsets这样做:

self.navigationItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 20, 0, 0)

然后它被尖叫2]

1 个答案:

答案 0 :(得分:2)

您可以在按钮之前添加额外的间距项:

    let button = UIBarButtonItem(title: "<", style: .Plain, target: self, action: "someSelector")
    let spacing = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
    spacing.width = 20;
    navigationItem.leftBarButtonItems = [spacing, button]