I try to programmatically add UINavigationBar in my viewController, however I got the markup issue which makes my navigation bar title move to the top border of the safe area and I wonder how to move this title to the center of the navigation bar. I cannot find any margins, paddings or frame configurations for it. So my question is how to vertically center the content of UINavigationBar
This is the code of navigation bar creation:
private lazy var navItem: UINavigationItem = {
let item = UINavigationItem(title: R.string.localization.supportNavigationBarTittle())
return item
}()
private lazy var navBar: UINavigationBar = {
let bar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 60))
bar.setTitleVerticalPositionAdjustment(CGFloat(70), for: UIBarMetrics.default)
return bar
}()
And in the viewDidLoad
method I append my toolbar to the whole view
navBar.tintColor = .white
view.addSubview(navBar)
let doneItem = UIBarButtonItem(image: UIImage(named: R.image.crossIcon.name), style: .plain, target: self, action: #selector(selectorName(_:)))
doneItem.imageInsets = UIEdgeInsets.init(top: 16, left: 8, bottom: 20, right: 8);
navItem.leftBarButtonItem = doneItem
navBar.setItems([navItem], animated: false)
Unfortunately, I got this zero top margin title and I cannot even find the way of how to fix it.
P.S.
I am pretty new in ios development, so I can make a lot of stupid mistakes.