我有一个GeometryReader,它在.25/.75比例中正确地空格了两个输入字段。
问题是,几何读取器的高度形成一个完美的方格,其中高度与宽度相匹配。
是否有办法使高度与内部的内容相一致?
GeometryReader { geometry in HStack(spacing: 20) {
MsInputField(fieldInput: $country, placeholder: Text("P"))
.frame(
width: geometry.size.width * 0.25
)
MsInputField(fieldInput: $phone, placeholder: Text("Phone"), preIcon: "DropDown", postIcon: "DropDown")
}
}

发布于 2022-04-06 00:57:03
GeometryReader占用父视图中的可用空间,因此您需要为GeometryReader设置宽度和高度,也可以为其中的h堆栈设置高度和宽度。
GeometryReader { geometry in HStack(spacing: 20) {
MsInputField(fieldInput: $country, placeholder: Text("P"))
.frame(
width: geometry.size.width * 0.25
)
MsInputField(fieldInput: $phone, placeholder: Text("Phone"),
preIcon: "DropDown", postIcon: "DropDown")
}
}.frame(width:150,height:50,alignment:.center)https://stackoverflow.com/questions/71759625
复制相似问题