When I create even the simplest titleView and add it to the navigationItem I see an additional space on the left before the titleView. I'm attaching a screenshot from iPhone 13 Pro Max - on the left is iOS 16 and on the right is iOS 15
The code is:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .lightGray
let titleViewWidth = UIScreen.main.bounds.width
let titleView = UIView(frame: CGRect(x: 0, y: 0, width: titleViewWidth, height: 40))
titleView.backgroundColor = .red
navigationItem.titleView = titleView
}
In the view hierarchy I see the following
iOS 16
_UINavigationBarContentView
<_UINavigationBarTitleControl: 0x7f794e9079b0; frame = (20 2; 390 40); layer = <CALayer: 0x6000004c7960>>
<_UITAMICAdaptorView: 0x7f794df08e40; frame = (0 0; 390 40); autoresizesSubviews = NO; layer = <CALayer: 0x6000004d9aa0>>
iOS 15
<_UINavigationBarContentView: 0x7f8294f0c620; frame = (0 0; 428 44); layer = <CALayer: 0x600001cb0020>> layout=0x7f82965113c0
<_UITAMICAdaptorView: 0x7f829651b940; frame = (12 2; 404 40); autoresizesSubviews = NO; layer = <CALayer: 0x600001ca82a0>>
So there is difference in 8 pointsfrom both sides (16 points in total) on iOS 16 and I don't know how to overcome this