SwiftUI中的文本有额外的水平填充。这种额外的填充出现在某些设备(画布、模拟器和物理设备)中,如iPhone 14 Pro,而在其他设备中不存在,如iPhone 14 Pro Max(xCode版本14.2)。我希望将文本和H1对齐前导。如何删除额外的填充?
struct TestView: View {
var body: some View {
VStack {
HStack {
Text("H1")
.font(.custom("GillSans-bold", size: 18))
Spacer()
Image(systemName: "doc")
}
Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.")
.font(.custom("GillSans", size: 18))
.background(.cyan)
}
.background(.yellow)
.padding()
}
}
1条答案
按热度按时间nafvub8i1#
这不是填充。默认情况下,文本框会居中对齐,因此文本无法与屏幕完全对齐。因此,您可能需要执行以下操作:
你也可以像在第一行中一样,在
HStack
中添加Spacer
,这将把文本推到边缘。