ios - 如何在 SwiftUI 中创建粘底?
解决方案
如果我理解正确,您想要做的是垂直堆叠(VStack)
- 滚动视图
- 另一个 VStack(带有 Toggle 和 Button),在底部对齐:
VStack {
ScrollView {...} // 1
VStack { // 2
Toggle(...)
Button(...)
}
.frame(alignment: .bottom)
}
举个例子:
struct SwiftUIView: View {
@State private var checked: Bool = false
let text = String(repeating: "blabla ", count: 20)
var body: some View {
VStack {
ScrollView {
ForEach((1...100), id: \.self) {_ in
Text(text)
}
}
VStack {
Toggle(isOn: $checked, label: {
Text("I have read...")
})
Button("Enter") {
// action
}
.frame(maxWidth: .infinity)
.padding(.vertical)
.background(Color.red)
}
.padding()
.border(Color.black)
.frame(alignment: .bottom)
}
}
}
推荐阅读
- c++ - 进程在 code::blocks c++ 中返回 -1073741819 (0xC0000005)
- java - 使分形景观看起来更逼真
- amazon-web-services - 用于运行特定 Python 函数的 AWS 服务
- xamarin - Xamarin.Forms UWP 项目是否支持 Lottie 动画?
- java - 在while循环中输入带有System.out.format的命令
- gradle - Gradle:BuildListener#buildStarted(Gradle) 已被弃用
- python-3.x - 在 WSL 上配置 Tor + Selenium 以进行网络抓取
- pattern-matching - Elixir 模式匹配解释
- c# - 在 c# 中解压缩 gz 文件:System.IO.InvalidDataException:'存档条目是使用不受支持的压缩方法压缩的。'
- flutter - 未来
- >>' 不能分配给参数类型 'List