I've sample code for the reference which works fine prior iOS 26 but not in iOS 26.
class SampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let aTitleView = UIView()
aTitleView.backgroundColor = .gray
aTitleView.translatesAutoresizingMaskIntoConstraints = false
navigationItem.titleView = aTitleView
navigationItem.setHidesBackButton(true, animated: false)
navigationController?.edgesForExtendedLayout = .all
navigationController?.setNavigationBarHidden(false, animated: true)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.backIndicatorImage = UIImage()
navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
}
}
This view controller is inside a UITabBarController. The app has a UITabBarController as a home screen along with 3 tabs. You can consider the above controller for all 3 tabs.
Can anyone show me exactly where my code is wrong or what is missing?
HangarRash
16.4k5 gold badges29 silver badges63 bronze badges
asked Oct 1 at 9:22
Chetan Prajapati
2,33521 silver badges25 bronze badges
-
1Define "doesn't work". You say "This view controller is inside UITabBarController.". Is it in a navigation controller that is in the tab? If not then I am not surprised it isn't working.Paulw11– Paulw112025年10月01日 09:58:17 +00:00Commented Oct 1 at 9:58
1 Answer 1
For some reason iOS 26 requires explicit size for titleView. Add width and height constraints to aTitleView and it should appear on screen.
answered Oct 2 at 11:47
Piotr Tobolski
1,4069 silver badges22 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
HangarRash
Another option, if the title view is a custom view class, is to override the
intrinsicContentSize property to return a proper size for the view.Explore related questions
See similar questions with these tags.
default