简体   繁体   中英

Change SwiftUI ProgressView Color - macOS not iOS

I am attempting to create a white ProgressView spinner on macOS using SwiftUI / Swift 5.2 using:

ProgressView()
    .progressViewStyle(CircularProgressViewStyle(tint: Color.white))
    .accentColor(Color.white)

However this does not seem to change the color. I have googled and searched but cannot figure how to change the color.

Any help would be appreciated.

You need to give it a value . Without that, it just displays an infinite spinner, which progressViewStyle has no effect on.

struct ContentView: View {
    @State private var percentage = 0.6
    var body: some View {
        ProgressView(value: percentage) /// here!
            .progressViewStyle(CircularProgressViewStyle(tint: Color.red))
    }
}
Before After
无限旋转的微调器,不显示进度 圆形进度条,60%用红色填充

If you want the indefinite spinner to be white, try a colorScheme of .dark . This forces it to take on its dark mode appearance.

ProgressView()
    .colorScheme(.dark)
    .background(Color.black) /// for testing purposes

Result:

下方有黑色方块的白色微调器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM