Stepper

12/5/2021 swiftiosswiftui

# Stepper

文档:https://developer.apple.com/documentation/swiftui/stepper (opens new window)

用于执行语义上递增和递减动作的控件。

@State var quantity: Int = 0
Stepper(value: $quantity, in: 0...10, label: { Text("Quantity \(quantity)")})

如果您要一个自己管理的数据源的控件,可以这样写:

@State var quantity: Int = 0
Stepper(onIncrement: {
    self.quantity += 1
}, onDecrement: {
    self.quantity -= 1
}, label: { Text("Quantity \(quantity)") })
上次更新: 12/6/2021, 5:21:44 PM