When I creatе the simplest titleView with iOS 16 and add it to the navigationItem I see an additional space that I cannot remove in any way. I did not have this issue on iOS 15, does anybody know what can be done?
The issue I am trying to solve is that the titleView contains a label which gets misaligned on iOS 16. The label is on the most left side of the titleView and
- on iOS 15 the titleView itself is on 12 points from the left and right corner of the screen
- but on iOS 16 the titleView is on 20 points from the left and right corner of the screen and this unfortunately breaks the desired design
I'm attaching a screenshot from iPhone 13 Pro Max - on the left is iOS 16 and on the right is iOS 15:
I have a view controller wrapped in a navigation controller and this is the only code in the view controller
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.titleView = UIView(frame: CGRect(x: 0, y: 0, width: 404, height: 40))
view.backgroundColor = .lightGray
titleView.backgroundColor = .red
}
}
The frame of the navigationItem.titleView:
iOS 15: iPhone 13 Pro Max: <UIView: 0x7f85fda14d10; frame = (0 0; 404 40);>
iOS 16: iPhone 13 Pro Max: <UIView: 0x7f7894f157e0; frame = (0 0; 388 40);>
I've tried removing insets, margins, changing the width, changing the place where I set the view, nothing works and I am out of ideas