[英]Text() is adding extra leading trailing padding SwiftUI
Hi Im creating this design, with swiftUI but I can't figure out why the Text() is adding more padding to the string value, I just want it to the leading trailing, like margins嗨,我用 swiftUI 创建了这个设计,但我不知道为什么 Text() 会为字符串值添加更多填充,我只是希望它在前导尾随,比如边距
Result:结果:
Code:代码:
struct ProductDetailSwiftUIView: View {
var body: some View {
ZStack {
ScrollView {
VStack {
Rectangle()
.frame(height: 213)
.foregroundColor(Color.blue)
Text("Fresas Congeladas La Huerta 500g")
.foregroundColor(.black)
.font(Font.bodySemibold(22))
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity)
.background(Color.red)
.padding(.leading, 16)
.padding(.trailing, 16)
}
}.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
print("Hello world🚀")
} label: {
Label("Back", image: "cartLine")
}.overlay(Badge(count: 1))
}
}
}
}
}
At first Text is aligned centered in frame, so首先 Text 在框架中居中对齐,所以
Text("Fresas Congeladas La Huerta 500g")
.foregroundColor(.black)
.font(Font.bodySemibold(22))
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading) // << fix 1 !!
.background(Color.red)
.padding(.leading, 16)
.padding(.trailing, 16)
gives:给出:
At second SwiftUI Text does not allow orphan words.在第二个 SwiftUI 文本不允许孤立词。 See next for details https://stackoverflow.com/a/71698509/12299030
详情见下https://stackoverflow.com/a/71698509/12299030
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.