左栏按钮项对齐 - Swift



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

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)

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

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

相关内容

  • 没有找到相关文章

最新更新