SwiftUI 位置文本右下角?

fuz*_*oat 7 text swiftui vstack hstack

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

代码

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()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

看法

在此处输入图片说明

Asp*_*eri 13

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

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