11.4 C
Canberra
Saturday, July 26, 2025

ios – The way to make hierarchical view with nested youngster views in Swiftui


The way to make this utilizing Swiftui

I attempted to make this design in swiftui and it’s resembling as effectively however i do not assume this strategy is a cleaner method. I’m attaching my code beneath.

struct NewShapeView: View {

let properties: [Property]

var physique: some View {
    ForEach(properties) { property in
        VStack(alignment: .main, spacing: 0) {
            ForEach(property.zones.indices, id: .self) { index in
                LineView(zoneName: property.zones[index].identify)
                SubView(showVerticalLine: index != property.zones.indices.final)
                    
            }
        }
    }
}

}

struct LineView: View {

let zoneName: String

var physique: some View {
    HStack(alignment: .backside, spacing: 0) {
        Rectangle().body(width: 1, top: 40)
        Rectangle().body(width: 40, top: 1)
        Textual content(zoneName)
    }
}

}

struct SubView: View {

var showVerticalLine: Bool

var physique: some View {
    HStack(spacing: 0) {
        if showVerticalLine {
            Rectangle().body(width: 1, top: 40) // Lengthen the road by way of SubView
        }
        Spacer().body(width:  32, top: 36) // Modify the spacer width to align with the earlier line
        Picture(systemName: "speaker.wave.2.fill")
        Textual content("Some Paradise - L’impératrice")
            .font(.subheadline)
            .foregroundColor(.grey)
    }
}

}

I’m a newbie and dealing on my first manufacturing swiftui app. Any solutions and assist are welcomed.
Thanks upfront.

I attempted a hack of drawing a vertical line on the boundary of zone subview until final view is present in array.
I’m anticipating a cleaner strategy.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles