ajayb
ajayb

Reputation: 633

left bar button item alignment - Swift

i can't get my left bar button item to align vertically. Here is my current code:

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)
}

I have tried using :

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

but I can't get my vertical position to change. Any suggestions?

Upvotes: 0

Views: 2898

Answers (1)

Bliss
Bliss

Reputation: 575

You cannot align them, because they go with your navigationBar. However, you can get that, by adding subview, and aligning your items in subview. Or another way is to use UIEdgeInsets

Upvotes: 1

Related Questions