Ede*_*lla 2 xcode ios swift swiftui swiftui-text
您好,我使用 swiftUI 创建此设计,但我不明白为什么 Text() 会向字符串值添加更多填充,我只想将其添加到前导尾随,例如边距
结果:
代码:
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))
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
首先,文本在框架中居中对齐,因此
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)
Run Code Online (Sandbox Code Playgroud)
给出:
第二,SwiftUI Text 不允许孤立词。有关详细信息,请参阅下一步/sf/answers/5018895661/
| 归档时间: |
|
| 查看次数: |
2000 次 |
| 最近记录: |