How to make this using Swiftui
I tried to make this design in swiftui and it is resembling as well but i don’t think this approach is a cleaner way. I am attaching my code below.
struct NewShapeView: View {
let properties: [Property]
var body: some View {
ForEach(properties) { property in
VStack(alignment: .leading, spacing: 0) {
ForEach(property.zones.indices, id: .self) { index in
LineView(zoneName: property.zones[index].name)
SubView(showVerticalLine: index != property.zones.indices.last)
}
}
}
}
}
struct LineView: View {
let zoneName: String
var body: some View {
HStack(alignment: .bottom, spacing: 0) {
Rectangle().frame(width: 1, height: 40)
Rectangle().frame(width: 40, height: 1)
Text(zoneName)
}
}
}
struct SubView: View {
var showVerticalLine: Bool
var body: some View {
HStack(spacing: 0) {
if showVerticalLine {
Rectangle().frame(width: 1, height: 40) // Extend the line through SubView
}
Spacer().frame(width: 32, height: 36) // Adjust the spacer width to align with the previous line
Image(systemName: "speaker.wave.2.fill")
Text("Some Paradise - L’impératrice")
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
I am a beginner and working on my first production swiftui app. Any suggestions and help are welcomed.
Thanks in advance.
I tried a hack of drawing a vertical line on the boundary of zone subview till last view is found in array.
I am expecting a cleaner approach.