【发布时间】:2021-05-27 21:49:07
【问题描述】:
如果我的后端服务器向我发送的图像图标少于 7 个,我想将我的水平社交媒体图像列表居中。如果我收到 7 个社交媒体图标,它看起来不错,但如果我收到 2、3 或 5 个图标,我想显示它们始终处于中心位置。我的意思是;
在第二张图片中,您可以看到它们看起来是分开的,但我想将它们显示在中心位置,就像在一起一样。我该怎么做?
这是我的代码;
HStack(alignment:.center,spacing : 0) {
ForEach(data.options ?? [] , id:\.id) { item in
if item.icon != nil {
Image(uiImage:(item.icon ?? "").load())
.resizable()
} else {
GeometryReader { geometry in
Image(item.type ?? "")
.resizable()
.frame(width:UIScreen.main.bounds.width * 0.065,alignment:.center)
.frame(width:geometry.size.width / 1,height:25,alignment:.center)
}
}.padding(EdgeInsets(top: 0, leading: 0, bottom: UIScreen.main.bounds.height * 0.050, trailing: 0))
}
}
【问题讨论】: