【发布时间】:2021-07-07 08:10:41
【问题描述】:
我写了下面的代码,并在scrollview上将数据显示到Hstack中
在我的情况下,我从服务调用中收到 10 个项目,并在 Hstack 中显示了这些项目 当用户第一次进入屏幕时,前 5 天可见,
但我需要先显示最后 5 个日期。
第一次需要看到最后一个索引(进入屏幕时)。
即需要首先显示当前日期
HStack(alignment:.center){
GeometryReader{ proxy in
ScrollView(.horizontal) {
LazyHStack {
ForEach(days.indices, id: \.self) { i in
CalendarView(
number: days[i].number,
days: days[i].weekday,
color: days[i].isToday ? #colorLiteral(red: 0.9060331583, green: 0.2547450066, blue: 0.3359550834, alpha: 1) : #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1),
textcolor: days[i].isToday ? #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) : #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), proxy: proxy
)
.onTapGesture{
print(days[i])
// this is just for replacing the current selection
for j in days.indices { days[j].isToday = false }
days[i].isToday = true
}
}
}
}
}
}
.padding([.trailing,.leading],3)
【问题讨论】:
标签: swift swiftui calendar scrollview hstack