Tuesday 22 September 2020

SwiftUI Gradient rendering incorrect colors on simulator

When running on the simulator, Gradient is rendering colors incorrectly. When running on a device, Gradient renders the colors correctly. How can I get Gradient to render colors correctly on the simulator so that I can capture accurate screenshots?

Simulator versus device:

simulator device

Example View with Gradient:

struct GradientView: View {
    
    private static let backgroundGradientColors: [Color] = [.red, .blue]
    
    var body: some View {
        ZStack {
            GeometryReader { geometryReader in
                let gradient: Gradient = Gradient(colors: GradientView.backgroundGradientColors)
                RadialGradient(gradient: gradient,
                               center: .bottomTrailing,
                               startRadius: 0, endRadius: geometryReader.size.width)
                    .edgesIgnoringSafeArea(.all)
            }
        }
    }

}


from SwiftUI Gradient rendering incorrect colors on simulator

No comments:

Post a Comment