SwiftUI 2.0 进度组件 —— ProgressView
2021-02-19 本文已影响0人
刘铁崧
代码
import SwiftUI
import Combine
struct ContentView: View {
@State private var progressValue = 0.0
var body: some View {
VStack{
ProgressView("线性进度条...",value:progressValue,total:100)
.foregroundColor(.red)
.progressViewStyle(LinearProgressViewStyle(tint: .blue))
.onReceive(Timer.publish(every: 1.0, on: .main, in: .common).autoconnect(), perform: { _ in
if progressValue < 100{
progressValue += 10
}
})
ProgressView("圆形进度条", value: 10, total: 100)
.foregroundColor(.red)
.progressViewStyle(CircularProgressViewStyle(tint: .green))
}
}
}
效果