Group

Overview

In all views SwiftUI has a limit of 10 Buttons. Here Group helps to overcome that limit. ???

Subjects

Sample Codes

Overcomming the limit

Group {  // Since SwiftUI has a limit of 10 buttons in a view it had to be groupped
    Button("Bloom") { setFilter(CIFilter.bloom()) }
    Button("Crystallize") { setFilter(CIFilter.crystallize()) }
    Button("Edges") { setFilter(CIFilter.edges()) }
    Button("Gaussian Blur") { setFilter(CIFilter.gaussianBlur()) }
    Button("Noir") { setFilter(CIFilter.photoEffectNoir()) }
    Button("Pixellate") { setFilter(CIFilter.pixellate()) }
    Button("Pointillize") { setFilter(CIFilter.pointillize()) }
    Button("Sepia Tone") { setFilter(CIFilter.sepiaTone()) }
    Button("Unsharp Mask") { setFilter(CIFilter.unsharpMask()) }
    Button("Vignette") { setFilter(CIFilter.vignette()) }
}

Group {
    Button("Cancel", role: .cancel) { }
}

Source: HWS

...

Layout Toggle

struct UserView: View {
    var body: some View {
        Group {
            Text("Name: Paul")
            Text("Country: England")
            Text("Pets: Luna and Arya")
        }
        .font(.title)
    }
}

struct ContentView: View {
    @State private var layoutVertically = false

    var body: some View {
        Group {
            if layoutVertically {
                VStack {
                    UserView()
                }
            } else {
                HStack {
                    UserView()
                }
            }
        }
        .onTapGesture {
            layoutVertically.toggle()
        }
    }
}

Sources

Videos

Hacking with Swift / 100 Days / Day-96 - Using groups as transparent layout containers

Articles / Documents

See also

Last updated