In iOS 26, how can I group multiple Liquid Glass buttons into a single pill view instead of separate buttons that my code currently does.
Note that I need to use UIKit, not SwiftUI.
Below code:
import UIKit
import SnapKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let container = UIVisualEffectView()
let effect = UIGlassContainerEffect()
effect.spacing = 10
container.effect = effect
let uIStackView = UIStackView()
uIStackView.axis = .horizontal
uIStackView.addArrangedSubview(button(systemName: "arrow.uturn.backward"))
uIStackView.addArrangedSubview(button(systemName: "arrow.trianglehead.2.clockwise.rotate.90"))
uIStackView.addArrangedSubview(button(systemName: "speaker.wave.3.fill"))
uIStackView.addArrangedSubview(button(systemName: "star.fill"))
container.contentView.addSubview(uIStackView)
uIStackView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
view.addSubview(container)
container.snp.makeConstraints { make in
make.center.equalToSuperview()
}
}
func button(systemName : String) -> UIButton {
let config = UIImage.SymbolConfiguration(pointSize: 14)
let button = UIButton()
button.setImage(UIImage(systemName: systemName, withConfiguration: config), for: .normal)
button.configuration = .glass()
let padding = 15.0
button.configuration?.contentInsets = NSDirectionalEdgeInsets(top: padding, leading: padding, bottom: padding, trailing: padding)
return button
}
}
Gives:
As you can see, each button is being rendered as separate instead of a single pill like view.
This article uses glassEffectUnion to achieve it in SwiftUI. How can this be done in Swift instead of SwiftUI?
