左栏按钮项目对齐 - 斯威夫特

时间:2017-06-13 04:41:12

标签: ios swift user-interface

我无法让我的左栏按钮项目垂直对齐。这是我目前的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    var image = UIImage(named: "pinImage")
    image = image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)

    navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: UIBarButtonItemStyle.plain, target: self, action: #selector(handleMapView))
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "+", style: .plain, target: self, action: #selector(createTrip))
    navigationItem.leftBarButtonItem?.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Nunito", size: 48)!, NSForegroundColorAttributeName : UIColor(r: 123, g: 230, b: 200)], for: UIControlState.normal)
}

我尝试过使用:

navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(4, for: .default)

但我无法改变我的垂直位置。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您无法对齐它们,因为它们与您的navigationBar一起使用。但是,您可以通过添加子视图并在子视图中对齐项目来实现这一点。或者另一种方法是使用UIEdgeInsets