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:
And if I set the background coloration to pure white, it produces:
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?





