Noticed this issue only in iOS 18, no issue in earlier versions. The navigation bar is moving up from its original location. I am attaching the screenshots for reference. One screenshot was taken from iOS 18 where you can see the issue and one screenshot is from iOS 17 without any issue. I am sharing the code, no issue with title and color related code. Tried below solutions but nothing worked.
self.navigationController?.navigationBar.prefersLargeTitles = false
self.navigationController?.navigationBar.layoutIfNeeded()
self.navigationController?.navigationBar.layoutIfNeeded()
self.navigationItem.largeTitleDisplayMode = .inline
Below is the code where i am setting the navigation bar. Any information will be helpful.
override func viewWillAppear(_ animated: Bool) {
self.setupNavigationBar()
}
func setupNavigationBar() {
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.navigationBar.barTintColor = .white
self.navigationController?.navigationBar.tintColor = .darkGray
self.navigationController?.navigationBar.applyUnderline(borderColor: .blue,
borderHeight: 1)
self.navigationItem.applyOsirisDesignTokenToNavigationTitle(text: "Title", color: .black)
self.navigationItem.addLeftBackButton(target: self, action: #selector(pressedBackButton))
}
func applyUnderline(borderColor: UIColor?, borderHeight: CGFloat = Constants.bottomBorderHeight) {
self.shadowImage = UIImage(color: borderColor)
let borderLayer = CALayer()
borderLayer.backgroundColor = borderColor.cgColor
borderLayer.frame = CGRect(x: 0.0,
y: self.frame.height,
width: self.frame.width,
height: borderHeight)
self.layer.addSublayer(borderLayer)
}
func applyOsirisDesignTokenToNavigationTitle(text: String, color: UIColor) {
let navigationLabel = UILabel()
let navTitle = self.applyBoldStyling(text: text, font: font, color: color)
navigationLabel.attributedText = navTitle
self.titleView = navigationLabel
}
func applyBoldStyling(text: String, font: UIFont, color: UIColor) -> NSAttributedString {
return NSAttributedString(string: text, attributes: [.font : font, .foregroundColor: color])
}