Skip to content

Instantly share code, notes, and snippets.

@LukasCZ
Last active September 26, 2025 09:21
Show Gist options
  • Select an option

  • Save LukasCZ/9b8f74bf13e1c24244a6951490c4bf50 to your computer and use it in GitHub Desktop.

Select an option

Save LukasCZ/9b8f74bf13e1c24244a6951490c4bf50 to your computer and use it in GitHub Desktop.
Fix for broken layout of large navigation titles when building with Xcode 26 and running on iOS 18.
//
// LargeNavTitlesOniOS18Fixer.swift
//
// Created by Lukas Petr on 30.08.2025.
// Licensed under the MIT License.
// See https://opensource.org/licenses/MIT for details.
//
//
// When compiling with Xcode 26 and running on iOS 18, large navigation titles have wrong layout (no leading margin).
// In case Apple doesn't fix this for the iOS 26 RC, this class provides a clean workaround for this issue.
//
// Usage: Just call LargeNavTitlesOniOS18Fixer.shared.register(self.navigationController?.navigationBar)
// in -viewDidLoad and -viewDidAppear of your view controllers where you need the fix.
//
import UIKit
@objc public class LargeNavTitlesOniOS18Fixer : NSObject {
@objc public static let shared = LargeNavTitlesOniOS18Fixer()
@objc(registerNavigationBar:)
public func register(_ navigationBar: UINavigationBar?) {
guard let navigationBar, ProcessInfo.processInfo.operatingSystemVersion.majorVersion < 26 else {
return
}
if let largeTitleLabelView: UIView = navigationBar.subviews.first(where: { NSStringFromClass(type(of: $0)).contains("LargeTitleView") })?.subviews.first {
if largeTitleLabelView.frame.origin.x < 0.1 {
largeTitleLabelView.frame.origin.x = 16
}
largeTitleLabelView.addObserver(self, forKeyPath: "bounds", options: .new, context: nil)
}
}
public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let newFrame = change?[NSKeyValueChangeKey.newKey] as? CGRect, newFrame.origin.x < 0.1 {
(object as? UIView)?.frame.origin.x = 16
}
}
}
@LukasCZ
Copy link
Author

LukasCZ commented Aug 31, 2025

Ever since Xcode 16 and iOS 26 SDK beta 1, there has been this issue of missing left margin of large navigation titles on iOS 18:
Screenshot 2025-08-31 at 14 13 19

This code fixes it.

Usage

Call LargeNavTitlesOniOS18Fixer.shared.register(self.navigationController?.navigationBar) in -viewDidLoad() and -viewDidAppear() methods of your view controllers that are used as the root in a UINavigationController stack.

@riccardoch
Copy link

Another solution is to set UINavigationBar.appearance().layoutMargins.left = 16 in didFinishLaunchingWithOptions of AppDelegate for iOS below 26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment