
Я пытался сделать этот дизайн в SwiftUI, и он тоже похож, но я не думаю, что этот подход является более чистым. Я прикрепляю свой код ниже.
Код: Выделить всё
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)
}
}
}
Заранее спасибо.
Я попробовал нарисовать вертикальную линию на границе подпредставления зоны до тех пор, пока в массиве не будет найдено последнее представление.Я ожидаю более чистого подхода.
Подробнее здесь: https://stackoverflow.com/questions/790 ... in-swiftui