你好,我创建了一个4行的表单,每行包含一个文本和2个文本字段,正如你可以从图片中看到的,它们没有垂直对齐,我找不到对齐所有文本字段的方法,并修复文本字段的大小,其中一些是长的,其中一些是短的。
Section("Time Selection"){
HStack{
Text("OFF")
.foregroundStyle(.blue)
.font(.footnote)
TimeInsertView(localTime: $localChockOFF, localTimeDate: $localChockOFFDate, utcTime: $utcChockOFF, utcTimeDate: $utcChockOFFDate, selectedDate: $flightDate, TextBoxDescription: "Chock OFF")
}
HStack{
Text("Take OFF")
.foregroundStyle(.blue)
.font(.footnote)
TimeInsertView(localTime: $localChockIN, localTimeDate: $localChockINDate, utcTime: $utcChockIN, utcTimeDate: $utcChockINDate, selectedDate: $flightDate, TextBoxDescription: "Chock IN")
.onChange(of: utcChockINDate) {
totalBlock = dm.timeDifference(endDate: utcChockINDate, startDate: utcChockOFFDate)
}
}
HStack{
Text("Landing")
.foregroundStyle(.blue)
.font(.footnote)
TimeInsertView(localTime: $localTakeOFF, localTimeDate: $localTakeOFFDate, utcTime: $utcTakeOFF, utcTimeDate: $utcTakeOFFDate, selectedDate: $flightDate, TextBoxDescription: "Take Off")
}
HStack{
Text("IN")
.foregroundStyle(.blue)
.font(.footnote)
TimeInsertView(localTime: $localLanding, localTimeDate: $localLandingDate, utcTime: $utcLanding, utcTimeDate: $utcLandingDate, selectedDate: $flightDate, TextBoxDescription: "Landing")
.onChange(of: utcLandingDate) {
totalFlightTime = dm.timeDifference(endDate: utcLandingDate, startDate: utcTakeOFFDate)
}
}
HStack{
Text("Block Hours")
Spacer()
Text(totalBlock)
}
HStack{
Text("Flight Time")
Spacer()
Text(totalFlightTime)
}
}
2条答案
按热度按时间swvgeqrz1#
我会使用
Grid
。“网格”的工作就是对齐事物!假设
TimeInsertView
是一个HStack
,平均分配两个TextField
…这不依赖于最左边列的硬编码值。
Grid
在左列查找最宽的Text
,并相应地调整右列的宽度。xa9qqrwz2#
而不是试图改变输入你应该改变标签到一个给定的宽度和输入将自然填补其余的空间