SwiftUI 位置文本右下角?
SwiftUI position text bottom right?
在 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()
}
}
}
VIEW
试试这个(用 Xcode 11.4 / iOS 13.4 测试)
struct DisplayTwoView: View {
var body: some View {
ZStack(alignment: .bottomTrailing) {
Rectangle().foregroundColor(.blue)
Text("RABBITS").fontWeight(.black)
.padding()
}
}
}
在 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()
}
}
}
VIEW
试试这个(用 Xcode 11.4 / iOS 13.4 测试)
struct DisplayTwoView: View {
var body: some View {
ZStack(alignment: .bottomTrailing) {
Rectangle().foregroundColor(.blue)
Text("RABBITS").fontWeight(.black)
.padding()
}
}
}