美文网首页SwiftUI
SwiftUI 2.0 进度组件 —— ProgressView

SwiftUI 2.0 进度组件 —— ProgressView

作者: 刘铁崧 | 来源:发表于2021-02-19 21:46 被阅读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))
        }
    }
}

效果

相关文章

网友评论

    本文标题:SwiftUI 2.0 进度组件 —— ProgressView

    本文链接:https://www.haomeiwen.com/subject/icjzxltx.html