我目前在列表中有一些HStacks。

然而,奇怪的是,“攻击”文本比所有其他字段稍微偏右一些。这可能很难注意到,但它会让一切看起来有点不对劲。奇怪的是,当我尝试为它使用不同的图标时,这种情况不会发生,比如shield.checkerboard

下面是我在这里为每个单元格使用的代码:
struct StatCell: View {
var title: String
var imgName: String
var clr: Color
var value: Int
var body: some View {
HStack {
Image(systemName: imgName)
.font(.headline)
.foregroundColor(clr)
.imageScale(.medium)
Text(title)
.font(.headline)
.padding(.leading, 10)
Spacer()
Text("\(value)")
.font(.headline)
.foregroundColor(.gray)
}
}
}一般来说,我是Swift和iOS开发的新手,所以如果我弄错了任何术语,我很抱歉。如果任何人知道任何解决这个问题的方法,除了使用不同的图标,任何帮助都将不胜感激!
发布于 2021-01-14 02:16:08
Asperi的评论包含了这个答案,它解决了我的问题!
https://stackoverflow.com/a/61984317/14410812
将.frame(width: 28)放在图像上会将它们设置为相同的宽度,从而防止此问题。
https://stackoverflow.com/questions/65707085
复制相似问题