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!