HomeiOS DevelopmentiOS 26 UIButton prominentClearGlass icon coloration does not adapt to the brightness/darkness...

iOS 26 UIButton prominentClearGlass icon coloration does not adapt to the brightness/darkness of content material behind it


In iOS 26, I would like my UIButton to routinely adapt the icon coloration based mostly on the content material behind it. For instance, if there’s a scrolling desk view behind it and the content material turns into mild, then the button icon must be black. If content material is darkish, then icon must be white. The iOS UITabBar icons already do that.

How ought to I do that with UIButton of varied types: UIButton.Configuration.glass(), .clearGlass(), .prominentGlass(), .prominentClearGlass()?

Beneath instance reveals the problem:

import UIKit
import SnapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        view.backgroundColor = .lightGray
        
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.spacing = 20
        view.addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.heart.equalToSuperview()
        }
        
        let imageConfig = UIImage.SymbolConfiguration(pointSize: 22, weight: .daring, scale: .massive)
        
        let padding = 20.0
        
        [UIButton.Configuration.glass(),.clearGlass(),.prominentGlass(),.prominentClearGlass()].forEach { config in
                        
            let button = UIButton(configuration: config)
            button.setImage(UIImage(systemName: "sq..and.pencil", withConfiguration: imageConfig)?.withRenderingMode(.automated), for: .regular)
            button.configuration?.contentInsets = NSDirectionalEdgeInsets(prime: padding, main: padding, backside: padding, trailing: padding)
            stackView.addArrangedSubview(button)

            }
        
        }
        
    }

}

Above produces:

iOS 26 UIButton prominentClearGlass icon coloration does not adapt to the brightness/darkness of content material behind it

And if I set the background coloration to pure white, it produces:

enter image description here

As you possibly can see, the icon colors aren’t adapting for the content material behind them and thus onerous to learn. How is ready to archive this of their UITabBar icons?

enter image description here

enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments