gpt4 book ai didi

text - SwiftUI 位置文本右下角?

转载 作者:行者123 更新时间:2023-12-03 15:48:32 41 4
gpt4 key购买 nike

有没有更好的方法在 SwiftUI 中定位文本,在下面的示例中,我将文本定位在 ZStack 的右下角,它工作正常但似乎冗长,我是否缺少更简单的方法......橙色线是仅用于调试,以便间隔在 View 中可见。

代码

struct DisplayTwoView: View {
var body: some View {
ZStack {
Rectangle().foregroundColor(.blue)
Group {
VStack {
Spacer().frame(width: 5).background(Color.orange)
HStack {
Spacer().frame(height: 5).background(Color.orange)
Text("RABBITS").fontWeight(.black)
}
}
}.padding()
}
}
}

查看

enter image description here

最佳答案

试试这个(使用 Xcode 11.4/iOS 13.4 测试)

struct DisplayTwoView: View {
var body: some View {
ZStack(alignment: .bottomTrailing) {
Rectangle().foregroundColor(.blue)
Text("RABBITS").fontWeight(.black)
.padding()
}
}
}

关于text - SwiftUI 位置文本右下角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60991490/

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