SwiftUI 基础控件之Stepper 代码(2020版教程)

SwiftUI 基础控件之Stepper 代码(2020版教程)

Stepper简介

A control used to perform semantic increment and decrement actions.

用于执行语义增量和减量动作的控件

大白话:可以设置步长的步进控件

源码


import SwiftUI
import Combine

class BookingStore: ObservableObject {
    var objectWillChange = PassthroughSubject()
    var bookingName: String = "" { didSet { updateUI() }
    }
    var seats: Int = 1 { didSet { updateUI() }
    }
    func updateUI() { objectWillChange.send()
    }
    
}


struct ContentView: View {
    @ObservedObject var model = BookingStore()
    var body: some View {
        VStack {
            TextField("Your Name",text: $model.bookingName)
            Stepper("Seats : \(model.seats)",
                        value: $model.seats,
                        in:1...5)
        }
        
    }
    
    
}

效果

SwiftUI 基础控件之Stepper 代码(2020版教程)_第1张图片
image.png

更多SwiftUI教程和代码关注专栏

  • 请关注我的专栏 SwiftUI教程与源码

你可能感兴趣的:(SwiftUI 基础控件之Stepper 代码(2020版教程))