设置leftBarButtonItem垂直位置

时间:2015-09-09 10:17:12

标签: xcode swift

我试图给leftBarButtonItem一个上边距,但它不起作用。我可以向右移动但不能向下移动。

self.navigationItem.leftBarButtonItem?.setTitlePositionAdjustment(UIOffsetMake(10, 20), forBarMetrics: UIBarMetrics.Default)

水平参数10确实有效,它将标题移到右侧。 但是,无论我将其更改为什么数字,垂直参数20都不会执行任何操作。

整个代码:

let attributes = [NSFontAttributeName: UIFont.ioniconOfSize(24)] as Dictionary!
let newBackButton = UIBarButtonItem(title: String.ioniconWithName(Ionicon.ChevronLeft), style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton;
self.navigationItem.leftBarButtonItem?.setTitleTextAttributes(attributes, forState: .Normal)
self.navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(5, forBarMetrics: UIBarMetrics.Default)

1 个答案:

答案 0 :(得分:1)

尝试:

self.navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(5, forBarMetrics: UIBarMetrics.Default)