swift – Totally different UIBarButtonItem Look in iOS 26 Beta 4 In comparison with iOS 18 Model – The right way to Retain iOS 18 Type?

0
1
swift – Totally different UIBarButtonItem Look in iOS 26 Beta 4 In comparison with iOS 18 Model – The right way to Retain iOS 18 Type?


I am encountering a problem the place the identical code for making a UIBarButtonItem leads to completely different visible appearances between iOS 18 (or earlier) and iOS 26 Beta 4. I am testing on simulators and gadgets utilizing Xcode 26 beta 4.

In my app, I am setting a proper bar button merchandise in a view controller’s navigation bar with the next code:

func initView() {
    self.view.backgroundColor = .systemGray6
    self.title = "Title"
    self.preferredContentSize = CGSize(width: 500, top: 600)
    let cancelButton = UIBarButtonItem.init(title: "Shut", fashion: .plain, goal: self, motion: #selector(cancelAndBack))
    self.navigationItem.leftBarButtonItem = cancelButton
    if #out there(iOS 26.0, *) {
        let doneButton = UIBarButtonItem.init(title: "Performed", fashion: .distinguished, goal: self, motion: #selector(cancelAndBack))
        self.navigationItem.rightBarButtonItem = doneButton
    } else {
        let doneButton = UIBarButtonItem.init(title: "Performed", fashion: .carried out, goal: self, motion: #selector(cancelAndBack))
        self.navigationItem.rightBarButtonItem = doneButton
    }
    
}

For Cancel Button:

  • No express fashion is ready right here, so it defaults to .plain.
  • On iOS 18 and beneath, this seems as plain textual content with no background or rounded
    body, which is the specified look.
  • On iOS 26 Beta 4, it exhibits with a white
    background and rounded corners, which I do not need. I would like a transparent background with none rounding or body.

For Performed Button:

  • I observed that UIBarButtonItem.Type.carried out is deprecated in iOS 26 (as
    per documentation). So, I attempted utilizing .distinguished explicitly, however the
    look is completely different ion IOS 26 in in comparison with iOS 18.
  • it’s added system blue colour because the background colour of the button.

Query:
Is there a really helpful solution to obtain constant look throughout iOS 18 and iOS 26, particularly retaining the iOS 18 fashion (plain textual content, no background, no rounding) on iOS 26 gadgets?
Are there any new APIs or configuration choices in iOS 18 that I ought to use to override this default styling?
Or is that this a beta challenge that is perhaps resolved?

Totally Code:

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        // Create the button
        let button = UIButton(kind: .system)
        button.setTitle("Click on me", for: .regular)
        button.translatesAutoresizingMaskIntoConstraints = false
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        button.setTitleColor(.white, for: .regular)
        button.backgroundColor = .systemBlue
        button.layer.cornerRadius = 8
        
        
        // Add goal for button faucet
        button.addTarget(self, motion: #selector(buttonTapped), for: .touchUpInside)
        
        // Add button to view
        view.addSubview(button)
        
        // Arrange constraints to heart the button
        NSLayoutConstraint.activate([
            button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
    
    @objc func buttonTapped() {
        let exportViewController = ExportViewController()
        let navController = UINavigationController(rootViewController: exportViewController)
        navController.modalPresentationStyle = .formSheet
        
        self.current(navController, animated: true, completion: nil)
    }
}


import UIKit

class ExportViewController: UIViewController {
    
    
    func initView() {
        self.view.backgroundColor = .systemGray6
        self.title = "Title"
        self.preferredContentSize = CGSize(width: 500, top: 600)
        let cancelButton = UIBarButtonItem.init(title: "Shut", fashion: .plain, goal: self, motion: #selector(cancelAndBack))
        self.navigationItem.leftBarButtonItem = cancelButton
        if #out there(iOS 26.0, *) {
            let doneButton = UIBarButtonItem.init(title: "Performed", fashion: .distinguished, goal: self, motion: #selector(cancelAndBack))
            self.navigationItem.rightBarButtonItem = doneButton
        } else {
            let doneButton = UIBarButtonItem.init(title: "Performed", fashion: .carried out, goal: self, motion: #selector(cancelAndBack))
            self.navigationItem.rightBarButtonItem = doneButton
        }
        
    }
    
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        // Name initView first to arrange the fundamental view
        initView()
        
        // Create and add the label
        let helloLabel = UILabel()
        if #out there(iOS 26.0, *) {
            helloLabel.textual content = "Hiya iOS 26"
        } else {
            helloLabel.textual content = "Hiya iOS 18"
        }
        helloLabel.font = UIFont.systemFont(ofSize: 48)
        helloLabel.textAlignment = .heart
        helloLabel.translatesAutoresizingMaskIntoConstraints = false
        
        view.addSubview(helloLabel)
        
        // Heart the label within the view
        NSLayoutConstraint.activate([
            helloLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            helloLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
    }
    
    @objc func cancelAndBack(){
        self.dismiss(animated: true, completion: nil)
    }
    
}

Please, refer connected screenshot for button look .

iOS 18 appearance
iOS 26 appearance

LEAVE A REPLY

Please enter your comment!
Please enter your name here