gpt4 book ai didi

layout - 如何在 SwiftUI 底部对齐文本

转载 作者:行者123 更新时间:2023-12-04 07:30:18 25 4
gpt4 key购买 nike

我的代码如下:

struct DotView: View {
var body: some View {
GeometryReader { geo in
let width = geo.size.width
HStack() {
VStack() {
Circle()
.frame(width: width, height: width)
Spacer()
Circle()
.frame(width: width, height: width)
}
}

}
}
}


struct TestView: View {
var body: some View {
HStack() {
Text("09")
DotView()
.frame(width: 7, height: 30, alignment: .center)
Text("22")
Text("PM")
.font(.system(size: 20))
}
.font(.system(size: 66, weight: .medium))
}
}

struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
结果如下图所示,所有 View 都在中心对齐。
Text
如何使“pm”在底部对齐“09”和“22”,例如波纹管图片?
Text

最佳答案

您可以将 VStack 与 Spacer() 一起使用并为 HStack() 设置框架

struct TestView: View {
var body: some View {
HStack() {
Text("09")
DotView()
.frame(width: 7, height: 30, alignment: .center)
Text("22")
VStack { // Added VStack with Spacer()
Spacer()
Text("PM")
.font(.system(size: 20))
}
}
.frame(width: 300, height: 55) // Added Line, adjust frame of HStack
.font(.system(size: 66, weight: .medium))
}
}
enter image description here

关于layout - 如何在 SwiftUI 底部对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67971025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com