ios - 如何在 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)
}
}
解决方案
为单元格创建一个结构(在您的代码中是 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()
}
}
推荐阅读
- csv - Azure 数据工厂转义字符和引用问题 - 复制活动
- pandas - 比较 pandas 中的行并填充空条目
- python-3.7 - 我想使用 python 将多个 TXTS 合并为一个 TXT,但它向我显示“io.UnsupportedOperation: not writable”。有没有人可以帮忙谢谢
- python - pandas groupby中的条件赋值
- svg - 为什么当我更改 viewBox 属性时我的 SVG 没有缩放
- forms - 带有 V-For 的动态 V 模型
- c# - 如何在 C# 中获取所选 IME 的名称?
- flutter - 在 Flutter 的 navigator.pop() 上显示 SnackBar?
- node.js - '。' 不被识别为内部或外部命令,
- php - URL 在浏览器和 Postman 中有效,但在 cURL 中无效