【发布时间】:2021-12-22 12:09:31
【问题描述】:
我正在使用 SwiftUI,我的 HStack 文本与他们的 lastTextBaseline 对齐。
但是文本上方有一个巨大的空间,整个堆栈不能在屏幕的中心。
看起来像这样:
我的代码:
struct SwiftUIViewTest: View {
var body: some View {
GeometryReader{ geometry in
ZStack{
Rectangle()
VStack(alignment: .center){
HStack(alignment: .lastTextBaseline){
Text("3")
.lineLimit(1)
.foregroundColor(Color.white)
.frame(width: nil, height: (geometry.size.height-10)/2.5, alignment: Alignment(horizontal: .center, vertical: .firstTextBaseline))
.font(.bold(.system(size: 100))())
.minimumScaleFactor(0.1)
.lineLimit(1)
.shadow(radius: 2)
Text("cups")
.foregroundColor(Color.white)
.font(.system(size: 12))
.shadow(radius: 2)
}
Text("next cup on")
.foregroundColor(Color.white)
.font(.system(size: 10))
.shadow(radius: 2)
.opacity(0.5)
Text("10 : 00")
.foregroundColor(Color.white)
.font(.system(size: 12))
.shadow(radius: 1)
.opacity(0.5)
}
}
.ignoresSafeArea()
}
}
}
【问题讨论】: