看起来 Stepper 表现得像一个灵活的视图,并尝试占用所有可用的宽度。但我希望它可以收缩到最小宽度。 考虑以下视图:
struct CartListCell: View {
@State var itemTitle = "Title"
@State var price = Double.random(in: 1...100)
@State var quantity = 1
var body: some View {
HStack(spacing: 10) {
Image(systemName: "cart")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
.foregroundStyle(Color.yellow, Color.cyan)
VStack(alignment: .leading, spacing: 5) {
Text(itemTitle)
.font(Font.system(.headline, design: .rounded))
.foregroundColor(.primary)
.lineLimit(2)
Text(price, format: .currency(code: Locale.current.currencyCode!))
.font(Font.system(.footnote, design: .rounded).weight(.medium))
.foregroundColor(.secondary)
}
.padding(.horizontal)
Spacer()
Stepper("x \(quantity)", value: $quantity, in: 1...50)
}
}
}
它产生了以下布局,其中Stepper
占据了HStack
一半的宽度。
如何去除"x1"文本和步进按钮之间的空格?