8.5 C
Canberra
Wednesday, December 3, 2025

View controller title colour not inverting primarily based on background


Utilizing Xcode 26.0.1 and working on iOS Simulator "iPad (A16)" with iOS 26.0.1.

I’m presenting a view controller as Full Display screen in a navigation controller.
It has a leftBarButtonItem, rightBarButtonItem, and a title.
It additionally has a picture view displaying a picture with a white background (the picture just isn’t full display).

The leftBarButtonItem’s textual content and background colours appear to robotically modify primarily based on the underlying picture colour and lightweight/darkish mode. The title’s textual content colour, nevertheless, doesn’t and solely makes use of the system textual content colour primarily based on mild/darkish mode.

Right here is how the view controller is offered:

@IBAction func loginPressed(_ sender: Any) {
    let lvc = LoginViewController()
    lvc.delegate = self
    let nc = UINavigationController(rootViewController: lvc)
    nc.modalPresentationStyle = .fullScreen
    self.current(nc, animated: true)
}

Right here is the viewDidLoad of LoginViewController:

override func viewDidLoad() {
    tremendous.viewDidLoad()
    
    self.title = "My Title"
    
    self.view.backgroundColor = .systemBackground
    
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Assist", model: .plain, goal: nil, motion: nil)
    
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .carried out, goal: self, motion: #selector(doneTapped))
    
    let iv = UIImageView()
    iv.picture = UIImage(named: "ImageWithWhiteBackground")
    iv.contentMode = .scaleAspectFit
    iv.translatesAutoresizingMaskIntoConstraints = false
    self.view.addSubview(iv)
    let wc = NSLayoutConstraint(merchandise: iv, attribute: .width, relatedBy: .equal, toItem: self.view, attribute: .width, multiplier: 1, fixed: 0)
    let hc = NSLayoutConstraint(merchandise: iv, attribute: .peak, relatedBy: .equal, toItem: self.view, attribute: .peak, multiplier: 1, fixed: 0)
    let xc = NSLayoutConstraint(merchandise: iv, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1, fixed: 0)
    let yc = NSLayoutConstraint(merchandise: iv, attribute: .centerY, relatedBy: .equal, toItem: self.view, attribute: .centerY, multiplier: 1, fixed: 0)
    self.view.addConstraints([wc, hc, xc, yc])
}

That is how the view controller seems in Mild Mode in Portrait and Panorama:

View controller title colour not inverting primarily based on background

LightMode Landscape Title visible

The leftBarButtonItem and title textual content colours are darkish as a result of it is Mild Mode — the whole lot is seen and readable.

That is how the view controller seems in Darkish Mode in Portrait and Panorama:

DarkMode Portrait Title visible

The leftBarButtonItem and title textual content colours are mild as a result of it is Darkish Mode — the whole lot is seen and readable. The picture peak is lower than the display so the view controller’s view (with background colour set to systemBackground) is seen at high and backside. Discover the leftBarButtonItem is white textual content on a black background (for Darkish Mode).

DarkMode Landscape Title invisible

In panorama, the picture peak is the same as the display so it is white at high and backside.
Discover the leftBarButtonItem is now black textual content on a white background (despite the fact that it is Darkish Mode).
However the title continues to be white making it invisible.
A aspect situation is the standing bar can be invisible and unreadable.

Is it doable to make the view controller’s title behave just like the leftBarButtonItem in order that it modifications colours primarily based on the underlying background?

Or, what’s the advised or advisable resolution for this?

I additionally tried setting self.navigationItem.titleView to a UILabel with "My Title" however that had the identical situation as utilizing self.title.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles