Posts

Post not yet marked as solved
0 Replies
304 Views
In the attached project file I used the LinearGradient command to fill the background of the whole screen with a color in the .displayP3 colorspace. I set the start and end color of the gradient to the same color so that it produces a simple solid color rather than a gradient. On top of that, I placed a rounded rectangle object and filled it with a solid fill of the same color variable in the displayP3 color space. Since the rectangle and the background are both filled with the same color, we should not be able to see the rectangle. However, the rectangle fill is correctly drawn using the .displayP3 colorspace while the LinearGradient fill is not. Therefore you can see the difference in color between the rectangle and the background. You can see the error for yourself by creating a new Xcode swiftUI project and pasting the code below into ContentView.swift. You will not see the error by running on the simulator. I only see it when I run it on my iPhone 11. // ContentView.swift // LinearGradientP3Color // import SwiftUI struct ContentView: View { let color1 = Color(.displayP3, red: 0.0/255.0, green: 123.0/255.0, blue: 184.0/255.0) var body: some View { VStack { // this rectangle displays with the correct color. The background does not. RoundedRectangle(cornerSize: CGSize(width: 10.0, height: 10.0)) .frame(maxWidth: .infinity,maxHeight: .infinity) .foregroundColor(color1) } .frame(maxWidth: .infinity,maxHeight: .infinity) .padding() .background( LinearGradient(gradient: Gradient(colors: [color1, color1]), startPoint: .top, endPoint: .bottom) ) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Posted Last updated
.