HomeiOS DevelopmentiOS 26, utilizing Swift, how can I group a number of Liquid...

iOS 26, utilizing Swift, how can I group a number of Liquid Glass buttons right into a single capsule view


In iOS 26, how can I group a number of Liquid Glass buttons right into a single capsule view as an alternative of separate buttons that my code presently does.

Be aware that I want to make use of Swift, not SwiftUI.

Under code:

import UIKit
import SnapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        
        let container = UIVisualEffectView()
        
        let impact = UIGlassContainerEffect()
        impact.spacing = 10
        container.impact = impact
        
        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.middle.equalToSuperview()
        }
    }

    func button(systemName : String) -> UIButton {
        let config = UIImage.SymbolConfiguration(pointSize: 14)
        
        let button = UIButton()
        button.setImage(UIImage(systemName: systemName, withConfiguration: config), for: .regular)
        button.configuration = .glass()
        let padding = 15.0
        button.configuration?.contentInsets = NSDirectionalEdgeInsets(high: padding, main: padding, backside: padding, trailing: padding)
        
        
        return button
    }

}

Provides:

iOS 26, utilizing Swift, how can I group a number of Liquid Glass buttons right into a single capsule view

As you may see, every button is being rendered as separate as an alternative of a single capsule like view.

I learn the beneath article:

https://www.donnywals.com/grouping-liquid-glass-components-using-glasseffectunion-on-ios-26/

which makes use of glassEffectUnion to attain it in SwiftUI. How can this be performed in Swift as an alternative of SwiftUI?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments