I want to show text combine with Rectangle as below image. I have already draw it in sketch by Combined Shape of Difference mode.
I code it in Xcode by SwiftUI, the code show as below:
struct DiffView: View {
var body: some View {
ZStack() {
Rectangle()
.fill(Color.blue)
.frame(width: 50, height: 50, alignment: .center)
Text("DIFF")
.foregroundColor(Color.blue)
.font(.system(size: 30, weight: .bold, design: .rounded))
.blendMode(.difference)
.offset(x: 20, y: 0)
}
.frame(width: 100, height: 100, alignment: .center)
.background(Color.white)
}
}
But the result is not as expected as in Sketch, the overlapping part on the left becomes black (expected to be white), and the letter on the right becomes yellow (expected to be blue).
How should I use swiftui blendMode correctly?enter code here