[英]SwiftUI position text bottom right?
Is there a better way of positioning text in SwiftUI, in the example below I am positioning the text in the bottom right corner of a ZStack, it works fine but seems long winded, am I missing a simpler way ... The orange lines are just for debugging, so that the spacers are visible in the view.有没有更好的方法在 SwiftUI 中定位文本,在下面的示例中,我将文本定位在 ZStack 的右下角,它工作正常但似乎冗长,我错过了一个更简单的方法......橙色线是仅用于调试,以便垫片在视图中可见。
CODE代码
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()
}
}
}
VIEW看法
Try this one (tested with Xcode 11.4 / iOS 13.4)试试这个(用 Xcode 11.4 / iOS 13.4 测试)
struct DisplayTwoView: View {
var body: some View {
ZStack(alignment: .bottomTrailing) {
Rectangle().foregroundColor(.blue)
Text("RABBITS").fontWeight(.black)
.padding()
}
}
}
Another way is via the .frame
modifier, like this:另一种方法是通过
.frame
修饰符,如下所示:
ZStack {
Text("RABBITS")
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.