2

I have a custom left bar button item, a custom title view, and a custom right bar button item. They are all fixed space items, with the rightBarButton view being defined in the storyboard, and the left and title views defined in code. They are added to the navigation bar as follows:

let leftButton = UIBarButtonItem()
leftButton.customView = myLeftBarView
navigationItem.leftBarButtonItem = leftButton

let rightButton = UIBarButtonItem()
rightButton.customView = myRightBarView
navigationItem.rightBarButtonItem = rightButton

navigationItem.titleView = myTitleView

This used to work fine when my rightBarButtonItem was small, however, now its around 80px wide and on smaller screen sizes (the iPhone 5 and 5s), the titleView is pushed over towards the left, and slightly overlaps my leftBarButtonItem.

How can I fix this?

Tometoyou
  • 7,792
  • 12
  • 62
  • 108

1 Answers1

0

I hope you have added left and right bar button items like this way.

let button: UIButton = UIButton (type: UIButtonType.Custom)
button.setImage(UIImage(named: "imageName"), forState: UIControlState.Normal)
button.addTarget(self, action: "backButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.frame = CGRectMake(0, 0, 30, 30)
let barButton = UIBarButtonItem(customView: button)

self.navigationItem.leftBarButtonItem = barButton

Method to call.

func backButtonPressed(btn : UIButton) {

}

Hope this will help you.

Hasya
  • 9,792
  • 4
  • 31
  • 46
  • Yes, all my bar button items are UIViews that are added as a customView to a `UIBarButtonItem`. That doesn't help though. – Tometoyou Nov 27 '16 at 12:35
  • Can you please write your whole left bar button, title and right bar button code in view willappear and update with your post, so we can see and help you ASAP. – Hasya Nov 27 '16 at 12:38
  • updated. The init code isn't included for the views, but they use autolayout. – Tometoyou Nov 27 '16 at 12:47
  • I believe your right bar button puts blank space, that's why tittle gets pushed towards left side and it overlays on left bar button.try doing with my code as button is getting created then adding in bar button item. Hope that will solve your problem. Also check this http://stackoverflow.com/questions/36709220/back-button-left-alignment-ios-9/36710897#36710897 – Hasya Nov 27 '16 at 13:48