san*_*orb 7 iphone ios swift swiftui
我在 ScrollView 中有 HStack,并且在 HStack 中有圆圈和文本。我怎样才能在圆圈之间画一条线?(这是巴士路线)
ForEach(stations, id: \.id) { station in
HStack{
Spacer().frame(width: 20)
Circle()
.stroke(Color.black,lineWidth: 4)
.frame(width: 10, height: 10)
Spacer().frame(width: 20)
Text(station.name)
Spacer()
if station.id > 0 {
Text(String(station.id))
}
let time = getNextDepartureTime(id: station.id)
Text("\(time.hour):\(time.minute)")
Spacer().frame(width: 20)
}
}
Run Code Online (Sandbox Code Playgroud)
Raj*_*han 13
为单元创建一个结构体(即代码中的 HStack)。
// Content HStack cell view
struct ContentCellView: View {
var isLast: Bool = false
var body: some View {
VStack(alignment: HorizontalAlignment.leading, spacing: 0) {
HStack {
Image(systemName: "message.circle").frame(width: 30)
Text("Route")
Spacer()
Text("Time")
}
if !isLast {
Rectangle().fill(Color.blue).frame(width: 1, height: 14, alignment: .center).padding(.leading, 15.5)//.offset(y: -10)
}
}
}
}
struct ContentView: View {
var body: some View {
ScrollView{
VStack(spacing: 0){
ForEach((1...10).reversed(), id: \.self) {
ContentCellView(isLast: $0 == 1) // isLast for not showing last line in last cell
}
}
}.padding()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15819 次 |
| 最近记录: |