1

Here is the code

[self presentViewController:viewController animated:YES completion:nil];

viewController is a UIImagePickerController

When I presented in viewController, navigationbar title shifted.

Please check the image.

I'm the image

Does anyone know how can I fix it?

Dmitry
  • 6,716
  • 14
  • 37
  • 39

2 Answers2

0

Using the following method to customize and change navigation bar button

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
 {
          //---> Code
 }

For more info seen the following link: Link

PT Vyas
  • 722
  • 9
  • 31
0

You need to give a constraint to titleView, from iOS11 navigation bar is playing with constraint instead of frames like before so,

public extension UIView {
//From iOS 11 -> UIBarButtonItem uses autolayout instead of dealing with frames. so adding contraint for the barbuttonItem
public func applyNavBarConstraints(size: (width: CGFloat, height: CGFloat)) {
    if #available(iOS 11.0, *) {
        let widthConstraint = self.widthAnchor.constraint(equalToConstant: size.width)
        let heightConstraint = self.heightAnchor.constraint(equalToConstant: size.height)
        heightConstraint.isActive = true
        widthConstraint.isActive = true
    }
}}

and use this as below:

navigationItem.titleView.applyNavBarConstraints(size: (width: viewWidth, height: viewHeight))

Hope this helps!

torap
  • 656
  • 6
  • 15